core.js: [BUG]: Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in

What happened?

How To fix?

Versions

Octokit.js v6.0.1, Node v18.19.1

Relevant log output

node:internal/errors:496
    ErrorCaptureStackTrace(err);
    ^
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /home/container/node_modules/@octokit/core/package.json
    at new NodeError (node:internal/errors:405:5)
    at exportsNotFound (node:internal/modules/esm/resolve:366:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:656:13)
    at resolveExports (node:internal/modules/cjs/loader:584:36)
    at Module._findPath (node:internal/modules/cjs/loader:658:31)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1120:27)
    at Module._load (node:internal/modules/cjs/loader:975:27)
    at Module.require (node:internal/modules/cjs/loader:1225:19)
    at require (node:internal/modules/helpers:177:18)
    at Object.<anonymous> (/home/container/index.js:31:21) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}
Node.js v18.19.1

Code of Conduct

  • I agree to follow this project’s Code of Conduct

About this issue

  • Original URL
  • State: closed
  • Created 4 months ago
  • Reactions: 2
  • Comments: 24 (14 by maintainers)

Commits related to this issue

Most upvoted comments

You can use dynamic imports, upgrade your code to ESM, or stick with v5

Option 1:

async function main() {
  const { Octokit } = await import('@octokit/core');

  const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });
}
main();

Option 2: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c tsconfig.json:

"moduleResolution": "node16",
"module": "node16",
"target": "es2022"

package.json:

"type": "module"

Option 3: package.json:

"@octokit/core": "^5"

The error in question in this issue is people that their code is CJS and are importing an ESM module.

There is also bugs with ts-node where it can’t handle ESM: https://github.com/TypeStrong/ts-node/issues/2094 https://github.com/TypeStrong/ts-node/issues/2100

At this point, there is nothing actionable on our part. This is user error

You are using CJS and not ESM. You will need to use dynamic imports or upgrade to ESM

    "target": "es2022",
     "module": "node16",
     "moduleResolution": "node16",