Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
cannot dynamic import from data-uri in jest

In the Node.js REPL I can dynamic import like this:

Welcome to Node.js v16.13.2.
Type ".help" for more information.
> let m = await import('data:text/javascript,export const x = 5;')
[Module: null prototype] { x: 5 }
> m.x
5
>

In pure Node.js, this also works:

//main.js
export const m = await import('data:text/javascript,export const x = 5;');
// index.js
import * as Main from './main.js';

console.log(Main.m.x);

and

$ node index.js
5
$

But this does not work in jest:

//main.test.js
import * as Main from './main.js';

test('it loads', () => {
  expect(Main.m.x).toEqual(5);
});

Get error:

Error: Cannot find module 'data:text/javascript,export const x = 5;' from 'main.js'

What's going on here?

My package.json (relevant parts):

{
  "type": "module",
  "scripts": {
    "test": "NODE_OPTIONS=--experimental-vm-modules jest"
  },
  "devDependencies": {
    "jest": "27.3.1"
  }
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!