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.

experimental-scope-hoisting throw error: ReferenceError: require is not defined

See original GitHub issue

🐛 bug report

when I enable experimental-scope-hoisting,the result will throw error:

ReferenceError: require is not defined

image

🎛 Configuration (.babelrc, package.json, cli command)

// .babelrc
{
  "presets": [
    ["@babel/env"],
    "@babel/typescript",
    ["@babel/react"]
  ],
  "plugins": [
    ["@babel/transform-runtime", {
      "corejs": 2
    }],
    "@babel/syntax-dynamic-import",
    ["@babel/proposal-decorators", {"legacy": true}],
    ["@babel/proposal-class-properties"],
    ["import", { "libraryName": "antd", "style": true, "libraryDirectory": "es" }]
  ],
  "env": {
    "development": {
      plugins: ["react-hot-loader/babel"]
    }
  },
  "sourceMaps": true,
  "retainLines": true
}
// package.json
build": "parcel build src/public/index.html --no-source-maps --experimental-scope-hoisting --no-minify",

🤔 Expected Behavior

enable --experimental-scope-hoisting should not throw error。

😯 Current Behavior

enable --experimental-scope-hoistingthrow error: ReferenceError: require is not defined

💁 Possible Solution

🔦 Context

💻 Code Sample

🌍 Your Environment

Software Version(s)
Parcel 1.12.3
Node 10.14.1
npm/Yarn 6.4.1
Operating System macOS

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
darioielardicommented, Jan 17, 2020

Unfortunately I’m not even using lodash, and I can’t figure out what’s causing the error.

1reaction
TakanashiOukencommented, Jan 7, 2020

Same issue here. No Solution for this? At least a workaround. In my html file, I do <script type="text/javascript"> window.require = function(e) { console.debug(“require hack still required //”, e); return undefined; }; </script> before loading any compiled JS, that at least allows things to proceed. Cheers!

Nice evil walk around. I turned to lodash-es to fix this issue but brings me to a next issue… Seems like _.clone will cause errors with tree shaking. $xxx$var$arrayBufferTag is undefined Orz

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Fix ReferenceError require is not defined in JavaScript
In this case, check your package.json file for an property called type . If that is set to module , ES6 modules will...
Read more >
require is not defined in ES module scope, you can use import ...
The error output is : Requiring external module babel-register ReferenceError: require is not defined in ES module ...
Read more >
Scope hoisting - Parcel
In production builds, Parcel concatenates modules into a single scope. This is called "scope hoisting". Parcel also statically analyzes the imports and ...
Read more >
babel require is not defined | The AI Search Engine You Control
bug report. when I enable experimental-scope-hoisting ,the result will throw error: ReferenceError: require is not defined.
Read more >
rollup.js
import the entire utils object with CommonJS const utils = require('. ... This will not throw an error if one of the entry...
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