parcel: Scope hoisting not working correctly with `import _ from “lodash”`
🐛 bug report
When I import lodash and build a really basic setup with --experimental-scope-hoisting, all browsers will display an error:
ReferenceError: require is not defined
This happens with:
import _ from "lodash"
or
var _ = require('lodash')
When --experimental-scope-hoisting is not used, this does not occur.
🎛 Configuration (.babelrc, package.json, cli command)
I did not use any custom babel configuration.
I’ve created a demo repository with the following package.json:
{
"name": "parcel-lodash-scope-hoisting-example",
"version": "0.0.1",
"main": "index.js",
"scripts": {
"dev": "parcel index.html",
"build": "parcel build index.html --public-url ./",
"build:scope-hoisting": "parcel build index.html --public-url ./ --experimental-scope-hoisting"
},
"repository": {
"type": "git",
"url": "git+https://github.com/maerteijn/parcel-lodash-scope-hoisting-example.git"
},
"devDependencies": {
"parcel-bundler": "^1.12.4"
},
"dependencies": {
"lodash": "^4.17.15"
}
}
🤔 Expected Behavior
A working bundle without JavaScript errors
😯 Current Behavior
A bundled JavaScript file which displays the error console message ReferenceError: require is not defined is all browsers.
🔦 Context
I can only reproduce this when I use lodash, and only with import _ from "lodash". With specific imports like:
import lowerCase from "lodash/lowercase"
all is fine.
(Probably) related issues: #3288 and #3625
💻 Code Sample
Reproducable when you use this repo: https://github.com/maerteijn/parcel-lodash-scope-hoisting-example
npm run build:scope-hoisting
Then open the built index.html in any browser. See also the README .
🌍 Your Environment
| Software | Version(s) |
|---|---|
| Parcel | 1.12.4 |
| Node | 12.16.1 |
| Lodash | 4.17.15 |
| npm/Yarn | 6.13.4 |
| Operating System | Mac OSX Mojave (10.14.6) |
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 2
- Comments: 21 (7 by maintainers)
Scope hoisting: way less bugs than Parcel 1, but not sure completely sure about “stable” Cache: not as stable Parcel 1 Code splitting: Parcel 2 does much more intelligent code splitting (shared bundles, also for workers), not sure how it compares to Parcel 1