Error: No "exports" main defined in package.json
See original GitHub issueDescribe the bug
Unable to run tests. Getting the following error Error: No "exports" main defined in /home/madhank/Desktop/git/learn-dsa/node_modules/vitest/package.json
Stack trace:
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FAIL bin/src/data-structures/single-linked-list/single-linked-list.spec.js [ bin/src/data-structures/single-linked-list/single-linked-list.spec.js ]
Error: No "exports" main defined in /home/madhank/Desktop/git/learn-dsa/node_modules/vitest/package.json
❯ src/data-structures/single-linked-list/single-linked-list.spec.ts:1:0
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
RangeError: Invalid count value
❯ generateCodeFrame node_modules/vitest/dist/chunk-vite-node-externalize.0791f2ed.mjs:10294:35
❯ node_modules/vitest/dist/chunk-vite-node-externalize.0791f2ed.mjs:10168:50
❯ printStack node_modules/vitest/dist/chunk-vite-node-externalize.0791f2ed.mjs:10258:32
❯ printError node_modules/vitest/dist/chunk-vite-node-externalize.0791f2ed.mjs:10163:3
❯ processTicksAndRejections node:internal/process/task_queues:96:5
❯ DefaultReporter.printTaskErrors node_modules/vitest/dist/chunk-vite-node-externalize.0791f2ed.mjs:7488:7
❯ DefaultReporter.reportSummary node_modules/vitest/dist/chunk-vite-node-externalize.0791f2ed.mjs:7434:7
❯ DefaultReporter.onFinished node_modules/vitest/dist/chunk-vite-node-externalize.0791f2ed.mjs:7293:5
❯ DefaultReporter.onFinished node_modules/vitest/dist/chunk-vite-node-externalize.0791f2ed.mjs:7627:5
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /home/madhank/Desktop/git/learn-dsa/node_modules/vitest/package.json
at new NodeError (node:internal/errors:372:5)
at throwExportsNotFound (node:internal/modules/esm/resolve:472:9)
at packageExportsResolve (node:internal/modules/esm/resolve:693:7)
at resolveExports (node:internal/modules/cjs/loader:482:36)
at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/home/madhank/Desktop/git/learn-dsa/src/data-structures/single-linked-list/single-linked-list.spec.ts:1:1) {
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}
Reproduction
Repo - https://github.com/madhank93/learn-dsa and run the command npm run test
System Info
System:
OS: Linux 5.14 Ubuntu 20.04.4 LTS (Focal Fossa)
CPU: (8) x64 Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz
Memory: 9.78 GB / 15.40 GB
Container: Yes
Shell: 5.8 - /usr/bin/zsh
Browsers:
Chrome: 103.0.5060.134
Firefox: 103.0
npmPackages:
vitest: ^0.18.0 => 0.18.0
Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created a year ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
No "exports" main resolved in /app/node_modules/@babel ...
Using npm update fixed the same error for me. ... The issue is that a new system for exports has been created, as...
Read more >No "exports" main defined in package.json · Issue #4138 · ipfs ...
ipfs@0.63.x is ESM-only, which means you can't use require to load it, you have to use import . Please see the upgrade guide....
Read more >No "exports" main defined - Laracasts
Hello , After cloning my project I got the error bellow when I npm run watch (I deleted the node_modules) ERROR in ./resources/js/app.js...
Read more >Modules: Packages | Node.js v19.3.0 Documentation
The "exports" provides a modern alternative to "main" allowing multiple entry points to be defined, conditional entry resolution support between environments, ...
Read more >Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No 'exports'
Run the npm update command to solve the "Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No 'exports'" and then run npm audit fix --force if necessary.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
On our end, the culprit was
eslint-import-resolver-alias
. Its last version is 4 years old, at a time where ESM support was not a topic. Node’s resolution logic assumes that it’s running in CommonJS, so it was looking for arequire
field in the relevantexport
inpackage.json
. There was none, so it crashed with this error. We fixed the problem by usingeslint-importe-resolver-customer-alias
, which is more recent and specifies to Node’s resolver that ESM is used, so that it looks at theimport
field instead.I was having similar issues with eslint import rules, error messages like that:
As suggested by @yacinehmito, replacing
eslint-import-resolver-alias
by the more recenteslint-import-resolver-custom-alias
fixed the problem.