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.

Uncaught ReferenceError: globalThis is not defined

See original GitHub issue

🐛 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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:17 (17 by maintainers)

github_iconTop GitHub Comments

2reactions
mischniccommented, Feb 2, 2021

I’m also somewhat surprised that @babel/preset-env doesn’t handle globalThis…

1reaction
mischniccommented, Feb 3, 2021

TIL: preset-env doesn’t really transpile API, only syntax. So we should transpile globalThis ourselves just like global (but probably only when it’s unsupported)

Read more comments on GitHub >

github_iconTop Results From Across the Web

ReferenceError: globalThis is not defined - npm - Stack Overflow
Consider updating your version of node.js to >=12 . globalThis was added in node.js v12.0.0 according to this compatibility table.
Read more >
ReferenceError: globalThis is not defined · Issue #2795 - GitHub
ReferenceError : globalThis is not defined at evalmachine.<anonymous>:1:1 at Script.runInContext (vm.js:133:20) at Object.
Read more >
globalThis is not defined although node version is v14.4.0
If you experience errors saying that globalThis is not defined, be sure to run a recent version of Node.js (at least 12.0). node...
Read more >
ReferenceError: globalThis is not defined - Ionic Framework
Hey guys its been weeks that my app was running great in broswer as serve or serve -l and on some android devices...
Read more >
ReferenceError: globalThis is not defined
Hey guys,. I am working on the ionic project and I am facing one issue. my app is working fine if I run...
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