parcel: Uncaught ReferenceError: globalThis is not defined
🐛 bug report
Compiling a package with Node (or Electron-renderer) context and using it triggers this error in some cases.
ReferenceError: globalThis is not defined
at /packages/linter-ui-default/dist/index.js:1:7989
at Se (/packages/linter-ui-default/dist/index.js:1:8142)
at oi (/packages/linter-ui-default/dist/index.js:1:44368)
at _e (/packages/linter-ui-default/dist/index.js:1:15274)
at _e (/packages/linter-ui-default/dist/index.js:1:7948)
at st (/packages/linter-ui-default/dist/index.js:1:15266)
at Qn.e.forEach.e (/packages/linter-ui-default/dist/index.js:1:83011)
at Array.forEach (<anonymous>)
at /packages/linter-ui-default/dist/index.js:1:82976)
at mn.updateTooltip (/packages/linter-ui-default/dist/index.js:1:89363)
at textEditor.onDidChangeCursorPosition (/packages/linter-ui-default/dist/index.js:1:88651)
at /packages/linter-ui-default/dist/index.js:1:41580)
at /packages/linter-ui-default/dist/index.js:1:41857)
at /packages/linter-ui-default/dist/index.js:1:41746)
🎛 Configuration (.babelrc, package.json, cli command)
"engines": {
"atom": ">=1.19.0 <2.0.0",
"electron": ">=5.x"
},
"targets": {
"main": {
"context": "node",
"includeNodeModules": {
"atom": false,
"electron": false,
"atom-package-deps": false,
"disposable-event": false
},
"outputFormat": "commonjs",
"isLibrary": true
}
},
"build": "cross-env NODE_ENV=production parcel build --target main ./lib/index.ts",
🤔 Expected Behavior
globalThis should not be needed?
😯 Current Behavior
Parcel generates globalThis
💁 Possible Solution
Use unbundled JS
🔦 Context
https://github.com/steelbrain/linter-ui-default/issues/617
💻 Code Sample
https://github.com/steelbrain/linter-ui-default
🌍 Your Environment
| Software | Version(s) |
|---|---|
| Parcel | “parcel”: “2.0.0-nightly.562”, |
| Node | 12 |
| npm/Yarn | 6 |
| Operating System | win 10 |
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 17 (17 by maintainers)
I’m also somewhat surprised that
@babel/preset-envdoesn’t handle globalThis…TIL: preset-env doesn’t really transpile API, only syntax. So we should transpile
globalThisourselves just likeglobal(but probably only when it’s unsupported)Parcel still excludes node_modules then 😬