Wasm-bindgen library and jest: Invalid or unexpected token @import"?

458 Views Asked by At

I'm trying to use jest in a react-typescript project that imports a rust/wasm library and while it works when I run the front-end, the jest test fails with:

/workspace/react-jest-rust/node_modules/rust-wasm-lib/index.js:73
export function message(s) {
^^^^^^
SyntaxError: Unexpected token 'export'

I've created an example, just run yarn test a after cloning: https://github.com/Findeton/react-jest-rust

I've tried configuring jest. If I add this to package.json:

  "jest": {
    "transformIgnorePatterns": [
      "node_modules/(?!rust-wasm-lib)/"
    ]
  }

Then I get this other error when running yarn test a:

/big/workspace/sequent/react-jest-rust/node_modules/rust-wasm-lib/index.js:125
    input = new URL('index_bg.wasm', import.meta.url);
                                            ^^^^

SyntaxError: Cannot use 'import.meta' outside a module

  2 | import logo from './logo.svg';
  3 | import './App.css';
> 4 | import init, {test} from 'rust-wasm-lib';
    | ^
0

There are 0 best solutions below