kriszyp / msgpackr

Ultra-fast MessagePack implementation with extension for record and structural cloning / msgpack.org[JavaScript/NodeJS]

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Identifier 'global' has already been declared

Plmeks opened this issue · comments

Hello
After last upgrade msgpackr as part of bull library started throwing an error in unit tests wit Jest environment:

.../node_modules/msgpackr/dist/node.cjs:984

let global = typeof globalThis === 'object' ? globalThis : window;
SyntaxError: Identifier 'global' has already been declared

Node.js 16.13
Jest 26.6.3
Bull 4.8.0 and msgpackr version inside bull is 1.9.0

@Plmeks Do you have any more information on how to reproduce this? When I install latest msgpackr I don't get this error (there is only one declaration of global in that file). I could change the name of that variable, but not sure how to verify the error/fix.

Same error here, happend while running "jest": "24.9.0"

@barriber same question, any idea how to reproduce this? Does jest do some type of module rewriting that yields this invalid syntax?

@kriszyp right now i can not provide working example. But @barriber is right - it is connected with jest environment and msgpackr. Jest has its own varaible global. And even executring jest with --inject-globals false is not fixing this. Working example - is to make some unit tests with jest, using msgpackr inside this test. In my case it is bull library (uses msgpackr), but it is very complicated to make fast-example with bull (redis needed) and jest in codesandbox.

Upgraded to latest jest and issue solved

Upgraded to latest jest and issue solved

Thank you, worked for me either!
Updated jest, ts-jest, ts-node

So do you think it would help to simply rename that variable (to glbl)?

Yes renaming solves the issue

Ok, I published a fix in 1.9.1

@kriszyp It works with the old version of jest, thank you.