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

🐛 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


About this issue

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

Most upvoted comments

Nice! Just tested 29.3.0 against the same demo project and it worked without a local patch! 🎉

I guess reading https://github.com/WebAssembly/esm-integration/tree/master/proposals/esm-integration is a start

(I can almost guarantee I won’t have the time or energy to work on this for some time, so if anybody wants to pick it up that’d be great!)