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
Clone my repo: git clone https://github.com/ottokruse/jest-subpath-import.git
Install dependencies: npm install
Run jest: npx jest
Expected behavior
Jest works fine, doesn't throw errors. Under the hood, jest thus understand subpath imports natively, as NodeJS does too. Subpath imports (link) were added to NodeJS in: v14.6.0, v12.19.0
Actual behavior
Jest errors with this message:
FAIL ./index.test.js
● Test suite failed to run
Cannot find module '#node-web-compat' from 'node_modules/aws-jwt-verify/dist/cjs/https.js'
Require stack:
node_modules/aws-jwt-verify/dist/cjs/https.js
node_modules/aws-jwt-verify/dist/cjs/jwk.js
node_modules/aws-jwt-verify/dist/cjs/jwt-rsa.js
node_modules/aws-jwt-verify/dist/cjs/index.js
index.test.js
at Resolver.resolveModule (node_modules/jest-resolve/build/resolver.js:324:11)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.283 s
Ran all test suites.
Additional context
Subpath imports (link) were added to NodeJS in: v14.6.0, v12.19.0
However Jest does not support modules using subpath imports, unless jest users do additional config (e.g. specify a moduleNameMapper in their config).
This is not obvious and requires users to waste time googling around looking for a fix.
The "fix", to add a moduleNameMapper in their config, is not a real fix, because it requires the developer to get to know, and use, the implementation details of the module with the subpath imports --> the user needs to copy paste the subpath import definition from the module's package.json into their jest config. This is of course also brittle:
module.exports={// To know what to put here I have to look inside the package.json of the module that has the// subpath import, and put the declaration here:moduleNameMapper: {"#subpath-import-name": "mapping-to-actual-js-file-or-external-module",},};
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.
Version
27.5.1
Steps to reproduce
Repo with reproducable case: https://github.com/ottokruse/jest-subpath-import
git clone https://github.com/ottokruse/jest-subpath-import.git
npm install
npx jest
Expected behavior
Jest works fine, doesn't throw errors. Under the hood, jest thus understand subpath imports natively, as NodeJS does too. Subpath imports (link) were added to NodeJS in: v14.6.0, v12.19.0
Actual behavior
Jest errors with this message:
Additional context
Subpath imports (link) were added to NodeJS in: v14.6.0, v12.19.0
However Jest does not support modules using subpath imports, unless jest users do additional config (e.g. specify a
moduleNameMapper
in their config).This is not obvious and requires users to waste time googling around looking for a fix.
The "fix", to add a
moduleNameMapper
in their config, is not a real fix, because it requires the developer to get to know, and use, the implementation details of the module with the subpath imports --> the user needs to copy paste the subpath import definition from the module's package.json into their jest config. This is of course also brittle:Environment
The text was updated successfully, but these errors were encountered: