Skip to content
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

ReferenceError: You are trying to import a file after the Jest environment has been torn down. #54

Open
lvl99 opened this issue Apr 15, 2021 · 4 comments

Comments

@lvl99
Copy link

lvl99 commented Apr 15, 2021

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.

@lvl99
Copy link
Author

lvl99 commented Apr 20, 2021

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.

@janmarcano
Copy link

bumping as I have the same issue

@lvl99
Copy link
Author

lvl99 commented Jan 24, 2022

Yep, my Cloud Build is still broken...

@juni0r
Copy link

juni0r commented Mar 25, 2022

I'm getting this error as well. Has anyone found a solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants