question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: No "exports" main defined in package.json

See original GitHub issue

Describe 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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
yacinehmitocommented, Aug 19, 2022

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 a require field in the relevant export in package.json. There was none, so it crashed with this error. We fixed the problem by using eslint-importe-resolver-customer-alias, which is more recent and specifies to Node’s resolver that ESM is used, so that it looks at the import field instead.

0reactions
fthebaudcommented, Aug 30, 2022

I was having similar issues with eslint import rules, error messages like that:

1:1   error    Resolve error: Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /home/fthebaud/Workspace/de.idnow.vi.web.frontend/node_modules/vitest/package.json
    at new NodeError (node:internal/errors:371:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:453:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:671:7)
    at resolveExports (node:internal/modules/cjs/loader:482:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
    at findModulePath (/home/fthebaud/Workspace/de.idnow.vi.web.frontend/node_modules/eslint-import-resolver-alias/index.js:99:27)
    at Object.exports.resolve (/home/fthebaud/Workspace/de.idnow.vi.web.frontend/node_modules/eslint-import-resolver-alias/index.js:75:10)
    at v2 (/home/fthebaud/Workspace/de.idnow.vi.web.frontend/node_modules/eslint-module-utils/resolve.js:116:23)
    at withResolver (/home/fthebaud/Workspace/de.idnow.vi.web.frontend/node_modules/eslint-module-utils/resolve.js:121:14)
    at fullResolve (/home/fthebaud/Workspace/de.idnow.vi.web.frontend/node_modules/eslint-module-utils/resolve.js:138:22)  import/namespace

As suggested by @yacinehmito, replacing eslint-import-resolver-alias by the more recent eslint-import-resolver-custom-alias fixed the problem.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found