'r' is not defined when building with Parcel.
See original GitHub issueThis is a great effort, loving it so far.
Building with Parcel and trying to run it I get.
Uncaught ReferenceError: r is not defined
As an ugly workaround I did like this:
import { r as a } from 'mobx-jsx'; const r = a;
And then it is defined in the scope. Any clues why rollup
and parcel
build output is different in this sense? Thanks.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Uncaught ReferenceError: require is not defined in Parcel v2
I expect to build properly without require which is node context. Current Behavior. It builds main bundle file with require keyword which is ......
Read more >ParcelJS does not bundle imported js library - Stack Overflow
Now when I run parcel build src/index.ts the output in the dist has: var $1ZQrD$pingmonitor = require("ping-monitor");. So the contents ...
Read more >How To Fix ReferenceError require is not defined in JavaScript
Your ReferenceError: require is not defined likely has one of two causes: You tried using require in a browser environment ...
Read more >Fix for require is not defined : r/node - Reddit
Hey there, try using a bundler to run your code. The easiest one is Parcel.js it's extremely fast, it gives you a live...
Read more >Scope hoisting - Parcel
When a non-static pattern is seen, Parcel creates an exports object that all importing modules access at runtime. All exports must be included...
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
Ok so the commonjs compiled version isn’t handling the named exports. Is it your intention (or Parcel’s) to for it to endup with commonjs require statements. I’m gathering this is because it’s being transpiled to ES5. Like for instance when I use Babel with webpack I set preset env with modules false to keep them as ES modules since webpack knows how to read them.
Even with require I would have expected it to assign the r var right after since the code is indicating that it wants that symbol. I suppose it could just mangle it throughout the rest of the file and still be consistent.
If atleast it is coming out at _mobxJsx.r. Your other option is to pass an optional argument to the babel-plugin-jsx-dom-expressions where you can can change what it uses for r. For example:
Pursuing a similar issue in Solid https://github.com/ryansolid/solid/issues/20 I realized there was an issue in the babel plugin. This should be fixed now so you shouldn’t have to do any of the special hacks. The default options should just work.