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.

Wasm es6 modules fail to load with Jest, but work in Node

See original GitHub issue

šŸ› Bug Report

I’m able to load an es6 module with Node, but I’m unable to load the same module when running with Jest. When I try loading the module with Jest, I get the following error:

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

(node:72954) ExperimentalWarning: VM Modules is an experimental feature. This feature could change at any time (Use node --trace-warnings ... to show where the warning was created) FAIL tests/test_jest.test.mjs ā— Test suite failed to run

/Users/me/projects/bin_packing/jest-wasm/node_modules/bin_packer_3d/bin_packer_3d_wasm_bg.wasm:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){


SyntaxError: Invalid or unexpected token

  at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)

To Reproduce

Steps to reproduce the behavior:

  1. Clone this repo: https://github.com/modulitos/jest-wasm-esm-example
  2. run npm run test-jest

Note that running npm run test-node loads the module successfully in Node. So why does it fail with Jest?

Expected behavior

The module loads when running npm run test-jest.

Link to repl or repo (highly encouraged)

https://github.com/modulitos/jest-wasm-esm-example

envinfo

āÆ npx envinfo --preset jest npx: installed 1 in 1.358s

System: OS: macOS 10.15.7 CPU: (4) x64 IntelĀ® Coreā„¢ i5-7360U CPU @ 2.30GHz Binaries: Node: 14.15.4 - ~/.asdf/installs/nodejs/14.15.4/bin/node npm: 6.14.10 - ~/.asdf/installs/nodejs/14.15.4/bin/npm npmPackages: jest: ^26.6.3 => 26.6.3


Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:24 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
kachkaevcommented, Nov 7, 2022

Nice! Just tested 29.3.0 against the same demo project and it worked without a local patch! šŸŽ‰

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest Typescript with ES Module in node_modules error
I was having the same problem with my svelte app and testing. I ultimately traced it to having a jest.config.js and a jest.config.json...
Read more >
ECMAScript Modules - Jest
Jest ships with experimental support for ECMAScript Modules (ESM). The implementation may have bugs and lack features. For the latest statusĀ ...
Read more >
Anyone gotten unit tests working with ES6 modules?
I've tried every variation of Jest + ES6, Jes… ... need Babel for what I what I was doing using the .mjs extension...
Read more >
Node.js v19.3.0 Documentation
JSON modules; Wasm modules; Top-level await; HTTPS and HTTP imports ... Using assert.fail() with more than two arguments is possible but deprecated.
Read more >
rewiremock - npm
for commonjs/nodejs use require('rewiremock/node') ... rewiremock.es6.js import rewiremock from 'rewiremock/webpack';Ā ...
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