You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use this module in a create-react-app project, and I'm trying to test my project with the built-in Jest test system.
Jest doesn't run Node in ESM mode; it can handle ESM code with import statements, but behind the scenes it does transpilation to run on require().
To use Jest with dependencies that are ESM modules, you have to add them to a negative regular expression in jest.transformIgnorePatterns in your package.json, so that Jest knows it needs to transpile them:
But even though Jest can transform this module just fine, it can't deal with the conditional export in this project's package.json, which only specifies a file to expose in "import" mode:
I get a Jest error like this when I try to run my tests:
> sequence-tube-maps@0.1.0 test
> react-scripts test --reporters default jest-compact-reporter --seed=1
Jest v27.5.1 node v18.7.0 darwin jest-min-reporter v0.1.0
Browserslist: caniuse-lite is outdated. Please run:
npx update-browserslist-db@latest
Why you should do it regularly: https://github.com/browserslist/update-db#readme
FAIL src/GBZBaseAPI.test.js
● Test suite failed to run
Cannot find module '@bjorn3/browser_wasi_shim' from 'src/GBZBaseAPI.mjs'
Require stack:
src/GBZBaseAPI.mjs
src/GBZBaseAPI.test.js
1 | import { APIInterface } from "./APIInterface.mjs";
2 | import { readFile } from "fs-extra";
> 3 | import { WASI, File, OpenFile, PreopenDirectory } from "@bjorn3/browser_wasi_shim";
| ^
4 |
5 | // TODO: The Webpack way to get the WASM would be something like:
6 | //import QueryWasm from "gbz-base/target/wasm32-wasi/release/query.wasm";
at Resolver.resolveModule (node_modules/jest-resolve/build/resolver.js:324:11)
at Object.<anonymous> (src/GBZBaseAPI.mjs:3:1)
If I add a "default": "./dist/index.js" export to this project's package.json in my node_modules, Jest can find it and import and transpile it.
There might be a way to give Jest a custom module resolver to work around this, but I think the configuration fields required are not among those that Facebook permits you to use in a create-react-app project.
It would be good if this project exposed an export like "default" that would work in this situation.
The text was updated successfully, but these errors were encountered:
I'm not familiar with how the node.js rules to determine which file to load for a module and whether to do so as ESM or CJS code. Would replacing the "import" with "default" break anything?
I think it would allow require() to try and import the module and fail if it can't be parsed. Right now require() shouldn't be able to see the module at all.
I went with the more conservative option of only adding the default key rather than replacing the module key with it in #65. Could you check if it works for you?
I'm trying to use this module in a
create-react-app
project, and I'm trying to test my project with the built-in Jest test system.Jest doesn't run Node in ESM mode; it can handle ESM code with
import
statements, but behind the scenes it does transpilation to run onrequire()
.To use Jest with dependencies that are ESM modules, you have to add them to a negative regular expression in
jest.transformIgnorePatterns
in yourpackage.json
, so that Jest knows it needs to transpile them:But even though Jest can transform this module just fine, it can't deal with the conditional export in this project's
package.json
, which only specifies a file to expose in "import" mode:browser_wasi_shim/package.json
Lines 25 to 26 in f1f5fd2
I get a Jest error like this when I try to run my tests:
If I add a
"default": "./dist/index.js"
export to this project'spackage.json
in mynode_modules
, Jest can find it and import and transpile it.There might be a way to give Jest a custom module resolver to work around this, but I think the configuration fields required are not among those that Facebook permits you to use in a
create-react-app
project.It would be good if this project exposed an export like "default" that would work in this situation.
The text was updated successfully, but these errors were encountered: