ReferenceError: You are trying to `import` a file after the Jest environment has been torn down.
I'm running my project within GCP Cloud Build and I'm getting the following error while running tests within Jest via NPM:
Step #1: ReferenceError: You are trying to `import` a file after the Jest environment has been torn down.
Step #1:
Step #1: at number (node_modules/gcp-metadata/node_modules/json-bigint/lib/parse.js:208:44)
Step #1: at value (node_modules/gcp-metadata/node_modules/json-bigint/lib/parse.js:397:41)
Step #1: at object (node_modules/gcp-metadata/node_modules/json-bigint/lib/parse.js:367:27)
Step #1: at value (node_modules/gcp-metadata/node_modules/json-bigint/lib/parse.js:389:16)
Step #1: at Function.parse (node_modules/gcp-metadata/node_modules/json-bigint/lib/parse.js:410:14)
When I look at the lines in gcp-metadata/node_modules/json-bigint/lib/parse.js:208 it seems that there's a require('BigNumber') which I think is causing the above issue in my test:
https://github.com/sidorares/json-bigint/blob/master/lib/parse.js#L208
I'm also importing BigNumber within my own project (in fact, in the tests that this error occurs, it's for functionality that I've built that relies on BigNumber) so I'm in a weird tricky spot where a dependency is doing magical things (gcp-metadata is being invoked during the test /somehow/) and a dependency of that (json-bigint) has an error which is completely halting my CI deployment process.
It seems like BigNumber should just be required at the top of the script (where you have var BigNumber = null) and avoid the inline import with conditional check on line 208. The conditional check seems like it should only require BigNumber if _options.useNativeBigInt is false.
This is really killing me. No idea how I can resolve this! What I thought would be a simple deployment has turned into hair pulling bald head episode.
bumping as I have the same issue
Yep, my Cloud Build is still broken...
I'm getting this error as well. Has anyone found a solution?