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.

[@jest/globals] Identifier 'jest' has already been declared

See original GitHub issue

šŸ› Bug Report

I, and probably many other people, love the idea of @jest/globals. Thanks again šŸ‘ Obviously, I just tried šŸ˜ƒ The FE part, ES modules transpiled with babel, seems to be just fine. The BE part is probably not expecting to import/require jest variable from @jest/globals

To Reproduce

const {jest} = require('@jest/globals')

Run the test

Error: SyntaxError: Identifier 'jest' has already been declared

Expected behavior

The test will pass the same way as without @jest/globals

Link to repl or repo

see the test file in https://repl.it/repls/LastingRepentantRuntimes

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13

github_iconTop GitHub Comments

1reaction
SimenBcommented, Apr 29, 2020

If I understand this correctly, the same would happen with the test file

Yup. Same in plain node

// file.js
const require = 42;
$ node file.js
/Users/simen/repos/infra/file.js:1
const require = 42
      ^

SyntaxError: Identifier 'require' has already been declared

Maybe we need to wrap in another function?

Weā€™ve stopped manually wrapping it in a function, which solves so many issues with source maps and code coverage (thereā€™s no offset) - we use vm.compileFunction instead. Or rather, we use it when available falling back to manual wrapper and vm.Script, and Iā€™m planning to remove vm.Script in Jest 26. Iā€™d really prefer some solution that didnā€™t require an extra function wrapper

0reactions
github-actions[bot]commented, May 10, 2021

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

jestjs - "Identifier 'global' has already been declared at ...
I upgraded my react project to use monaco-editor version 0.21.0, since then the jest tests for filesĀ ...
Read more >
Identifier 'jest' has already been declared in file 'dist\__tests__ ...
Fixing error: SyntaxError: Identifier 'jest' has already been declared in file 'dist\__tests__\import-editions-test.js'.
Read more >
Configuring Jest
Automatically clear mock calls, instances, contexts and results before every test. Equivalent to calling jest.clearAllMocks() before each test.
Read more >
@jest/globals | Yarn - Package Manager
npm version Jest is released under the MIT license. Follow on Twitter. GitHub CI Status Coverage Status. Gitpod ready-to-codeĀ ...
Read more >
jest cannot spy the property because it is not a function - You.com ...
d.ts:40:18 - error TS2300: Duplicate identifier 'xit'. 40 declare function xit(expectation: string, assertion?: (done: DoneFn) => void, timeout?: number): void;Ā ...
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