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.

[type] identifier 'global' has already been declared

See original GitHub issue

Fails to require @deepkit/type in a jest test suite, because global is a “reserved” identifier.

/node_modules/@deepkit/type/dist/cjs/src/model.js:23
    const global = {
          ^

    SyntaxError: Identifier 'global' has already been declared

      at Runtime.createScriptFromCode (../../../../../../../../../../node_modules/jest-runtime/build/index.js:1350:14)
      at Object.<anonymous> (../../../../../../../../../../node_modules/@deepkit/type/index.ts:12:1)

Here’s a quick fix for now using patch-package:

diff --git a/node_modules/@deepkit/type/dist/cjs/src/model.js b/node_modules/@deepkit/type/dist/cjs/src/model.js
index 5f1fec9..f6cdbce 100644
--- a/node_modules/@deepkit/type/dist/cjs/src/model.js
+++ b/node_modules/@deepkit/type/dist/cjs/src/model.js
@@ -20,11 +20,9 @@ var UnpopulatedCheck;
     UnpopulatedCheck[UnpopulatedCheck["Throw"] = 1] = "Throw";
     UnpopulatedCheck[UnpopulatedCheck["ReturnSymbol"] = 2] = "ReturnSymbol";
 })(UnpopulatedCheck = exports.UnpopulatedCheck || (exports.UnpopulatedCheck = {}));
-const global = {
-    RegisteredEntities: {},
-    unpopulatedCheck: UnpopulatedCheck.Throw,
-    enableForwardRefDetection: true,
-};
+global.RegisteredEntities = {};
+global.unpopulatedCheck = UnpopulatedCheck.Throw;
+global.enableForwardRefDetection = true;
 function getGlobalStore() {
     return global;
 }

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
marcjcommented, Jan 26, 2021

Mh ok, we can easily change that variable, no problemo.

0reactions
marcjcommented, Jan 28, 2021

is fixed in master

Read more comments on GitHub >

github_iconTop Results From Across the Web

Identifier 'global' has already been declared #104 - GitHub
When running a test that imports the module, it causes a duplicate identifier error to be thrown. This seems to be the cause ......
Read more >
jestjs - "Identifier 'global' has already been declared at ...
"Identifier 'global' has already been declared at compileFunction" error In jest tests after upgrading to monaco-editor 0.21.0.
Read more >
Identifier "x" has already been declared" - Ep 11 - YouTube
JS Casts 11 - How to fix "Uncaught SyntaxError: Identifier "x" has already been declared " in JavaScript.
Read more >
Getting a 'Uncaught SyntaxError: Identifier 'astrosUrl' has ...
Getting a 'Uncaught SyntaxError: Identifier 'astrosUrl' has already been declared. I don't know why I am getting this error as I don't see...
Read more >
Uncaught SyntaxError: Identifier has already been declared ...
The "const ' {a}' has already been declared" error is thrown when JSHint encounters a constant declaration with an identifier that has already...
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