-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[@jest/globals] Identifier 'jest' has already been declared #9920
Comments
Ah, didn't think about this case... It probably works for the transpiled case as the identifier will be named differently. We inject You can do The problem would go away if we introduced some sort of "no globals" mode, but ideally I'd like these to work together. @jeysal @thymikee any good ideas here? I guess we could do some weird stuff with the babel plugin, but I don't think the babel plugin should be required |
If I understand this correctly, the same would happen with the test file: const jest = 42; If so, this is a way more general bug? We should inject things into a higher scope than the program scope of the file. Maybe we need to wrap in another function? |
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
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 |
Oh. Hmm, then allowing to declare |
If this happens any time soon and it solves the issue, then the workaround is sufficient for now. On the other hand, the documentation mentions FYI, another workaround that could help somebody is to use a scoped variable, e.g. const {
describe,
} = require('@jest/globals')
describe('suite', () => {
const {jest} = require('@jest/globals')
}) |
Encountered something similar. Moving |
Oh, interesting! That's probably a bug in the new implementation in the babel plugin. Can you open up an issue with a reproduction? |
@SimenB I'll see if I can reproduce it in a new project with a setup similar to mine. It indeed started happening after I updated babel-plugin. |
We rewrote the plugin in order to support |
Circling back to this issue, we now have a |
Great 🎉 , seems to work, thanks!!! |
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. |
🐛 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
The text was updated successfully, but these errors were encountered: