Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest tests started failing with TypeError: A dynamic import callback was invoked without --experimental-vm-modules after recent React Native upgrade

I've been trying to resolve this test error for a while now with not success. Recently I upgraded React Native from 0.72.3 to 0.74.3 and got the Android application to build and run, however, I can't get all the tests to pass. I am currently getting the following error:

TypeError: A dynamic import callback was invoked without --experimental-vm-modules

Inside my icons.ts file which dynamically lazy loads icons the following way:

const Icons = {
    sun: lazy(() => import('@src/assets/icons/sun.svg')),
    moon: lazy(() => import('@src/assets/icons/moon.svg')),
    cloud: lazy(() => import('@src/assets/icons/cloud.svg')),
}

The tests were passing fine before, and now they no longer pass. I believe adding --experimental-vm-modules solves that specific error, but causes other errors and from what I've read, using that flag is not advised. Is there anything else I can do to resolve this issue?

like image 975
Bobimaru Avatar asked Jan 29 '26 22:01

Bobimaru


1 Answers

You have to execute Node with the --experimental-vm-modules flag. Here are two ways you can add this flag when running Jest:

node --experimental-vm-modules node_modules/jest/bin/jest.js

or

NODE_OPTIONS="$NODE_OPTIONS --experimental-vm-modules" npx jest

personally this is how I handle it in my package.json script

"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest --runInBand",

Source: Jest documentation

like image 56
Emanuele Caruso Avatar answered Feb 01 '26 13:02

Emanuele Caruso



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!