Skip to content

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

Closed
@modulitos

Description

@modulitos

🐛 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(R) Core(TM) 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


Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions