Error when parsing Mobx
See original GitHub issueEnvironment
npm ls
├── @babel/core@7.18.13
├── @linaria/babel-preset@4.1.2
├── @linaria/core@4.1.1
├── @linaria/webpack-loader@4.1.2
├── babel-loader@8.2.5
├── webpack-cli@4.10.0
└── webpack@5.74.0
node -v
v16.13.1
On macOS Monterey
Description
When I tried to update to the latest Linaria version, I ran into a strange parsing bug. Originally it failed on dist/mobx.esm.js from the popular MobX library.
I’ve boiled down the code to the following example:
// main.js
import { css } from "@linaria/core";
import { b } from "./mobx.js";
css``;
// mobx.js
var _;
var a = void _;
function b(b) {
void _;
}
export { a, b };
When trying to parse this, it will fail with:
ERROR in ./src/main.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /Users/jhnns/dev/jhnns/linaria-bug-repo/src/main.js: /Users/jhnns/dev/jhnns/linaria-bug-repo/src/mobx.js: Exporting local "b", which is not declared.
7 | }
8 |
> 9 | export { a, b };
| ^
Could be a Babel bug, but since it only happens in conjunction with Linaria I guess this is the right place to start 😁
Reproducible Demo
The example is pretty small and simple:
Issue Analytics
- State:
- Created a year ago
- Comments:5
Top Results From Across the Web
mobx + react unexpected token - Stack Overflow
I installed mobx and mobx-react ,but is still shows the error of unexpected token before @ symb. Do I need to add something...
Read more >mobxjs/mobx - Gitter
Hi All, does anyone facing this issue when trying to build? ERROR in node_modules/mobx/lib/types/observableset.d.ts(2,72): error TS1005: ';' expected.
Read more >mobx-observable-promise - npm
Observable promise implementation for mobx stores. ... You can track promise status using these fields (is executing?, completed?, error?)
Read more >Javascript parse fail if I use decorator for property in classes
import {observable} from "mobx"; class OrderLine { @observable price = 0; ... ERROR: Unable to parse file: /data/app/dropdown.js It report that could not ......
Read more >useField | @mozartspa/mobx-form - GitHub Pages
Common use cases include converting javascript Date values into a localized date string. Almost always used in conjunction with parse.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Yes, I also thought that this might be caused by multiple bugs.
That sounds good 😃
I’m only using
voidin order to mark the variable as used. You could also doconsole.log(). I’ve added the originalmobx.esm.json a separate branch: https://github.com/jhnns/linaria-bug-repo/tree/with-mobxStack trace
That was the actual error that I saw in my application. It was caused by
mobx-react-liteimporting_allowStateChangesfrom themobxlibrary.Awesome, thank you 😃
allowStateChangesis used bymobx-react-litewhich takes care of rerendering React components whenever Mobx observables change. Every React component will importmobx-react-litewhich will importallowStateChangesfrommobx. That’s why this code is evaluated by Linaria.