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.

Lost of context between tests when using dynamic ESM import

See original GitHub issue

🐛 Bug Report

When using dynamic imports from a class and then make use of this class in two separate test files, the VM environment context seems to be lost in one of the two files. This lead to an Invariant error in node_modules/jest-runtime/build/index.js:2004:11 without error message due to null condition (the context is used here as a condition).

This comportment creates a test result where one test suite is successful and the other one is failing.

Already opened a thread on stack overflow for this https://stackoverflow.com/questions/65256785/nodejs-import-issue-with-jest

To Reproduce

Steps to reproduce the behavior:

Create a class with a method that will make use of the dynamic ESM import() keyword and execute loading test in two separate testing files.

Full code with failing pipeline is available on this public Gitlab repository : https://gitlab.com/matthieu88160/stryker-issue

Expected behavior

The two test suites should succeed.

Link to repl or repo (highly encouraged)

https://stackoverflow.com/questions/65256785/nodejs-import-issue-with-jest

https://gitlab.com/matthieu88160/stryker-issue

envinfo

  System:
    OS: Linux 4.15 Ubuntu 20.04 LTS (Focal Fossa)
    CPU: (2) x64 Intel(R) Core(TM) i7-7567U CPU @ 3.50GHz
  Binaries:
    Node: 14.15.1 - /usr/local/bin/node
    npm: 6.14.9 - /usr/local/bin/npm
  npmPackages:
    jest: ^26.6.3 => 26.6.3 

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
SimenBcommented, Dec 13, 2020

Yeah, it’ll keep failing sporadically. Will need to track it down and fix, it was more an observation than something to remedy the situation

0reactions
SimenBcommented, Aug 8, 2022

I think this is a bug in Node, but we should track it still and verify once upstream is fixed

Read more comments on GitHub >

github_iconTop Results From Across the Web

import - JavaScript - MDN Web Docs - Mozilla
import defaultExport from "module-name"; import * as name from ... To load modules in non-module contexts, use the dynamic import syntax ...
Read more >
JavaScript modules: dynamic import() - CanIUse
Loading JavaScript modules dynamically using the import() syntax. Usage % of. all users, all tracked, tracked desktop, tracked mobile.
Read more >
ESLint - Error: Must use import to load ES Module
Run npm i from a terminal/command prompt in the folder; In .eslintrc, update the parser line "parser": "babel-eslint", to "parser": "@babel ...
Read more >
expected the result of a dynamic import() call. instead received
How am I to prevent network interaction from happening? How am I to test that I use the requests module properly? This is...
Read more >
ECMAScript modules | Node.js v19.3.0 Documentation
exports value. This Module Namespace Exotic Object can be directly observed either when using import * as m from 'cjs' or a dynamic...
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