question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'r' is not defined when building with Parcel.

See original GitHub issue

This 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:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ryansolidcommented, Jan 24, 2019

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.

presets: [['@babel/preset-env', {modules: false}]]

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:

plugins: [['jsx-dom-expressions', {moduleName: '_mobxJsx.r']]
0reactions
ryansolidcommented, Apr 15, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found