Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in #667

Closed
1 task done
Labels
released Status: Needs Info Full requirements are not yet known, so implementation should not be started Type: Bug Something isn't working as documented

Comments

@IchanZX1
Copy link

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
@IchanZX1 IchanZX1 added Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented labels Mar 13, 2024
Copy link
Contributor

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@wolfy1339
Copy link
Member

Please share reproducible code example

@wolfy1339
Copy link
Member

That specific error message suggest you are not using ESM.

Please see the usage section in the README:
https://github.com/octokit/core.js?tab=readme-ov-file#usage

@wolfy1339 wolfy1339 added Status: Needs Info Full requirements are not yet known, so implementation should not be started and removed Status: Triage This is being looked at and prioritized labels Mar 13, 2024
@clementhemidy
Copy link

clementhemidy commented Mar 14, 2024

Hi,

I have the same issue.

Error: No "exports" main defined in ***/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 Function.Module._findPath (node:internal/modules/cjs/loader:658:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1120:27)
    at Function.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> (***/src/github/github.repository.ts:1:1)

Octokit.js: v6.0.1
Node version: v18.19.1
Npm version: 10.2.4

I already use ESM to import the Octokit class:
import {Octokit} from "@octokit/core";

@wolfy1339
Copy link
Member

Are you using typescript at all? In typescript just because you are importing using ESM imports doesn't mean you are using ESM

@wolfy1339
Copy link
Member

If anyone is experiencing this issue, please give a small reproducible example in a separate repo.

Include the package.json and the tsconfig.json as well as a file that has the least code in order to reproduce the problem.

Also don't forget to specify the environment (Browser/Node/Deno as well as the version)

It would be very helpful in diagnosing this issue and helping out users.

You may also want to read up on ESM packages, https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

@iamnotstatic
Copy link

Anyone found a workaround for this, i'm also experiencing same issue

@wolfy1339
Copy link
Member

Anyone found a workaround for this, i'm also experiencing same issue

@iamnotstatic Please read my comment above.
Please provide all relevant information

@Darker935
Copy link

Darker935 commented Mar 20, 2024

@wolfy1339 https://github.com/Darker935/MdgWa-TEST

Run with npm run dev

@wolfy1339
Copy link
Member

wolfy1339 commented Mar 20, 2024

@Darker935 @octokit/rest is not an ESM module yet, you will have to downgrade @octokit/auth-token

Also, you are still using CJS in your example which explains some of the errors

@iamnotstatic
Copy link

Anyone found a workaround for this, i'm also experiencing same issue

@iamnotstatic Please read my comment above. Please provide all relevant information

Downgrading to 5.1.0 worked fine for me i will just stick to that for now

@wolfy1339
Copy link
Member

I understand that downgrading has solved the issue, I really wish to diagnose and fix this issue for users

@iamnotstatic
Copy link

I understand that downgrading has solved the issue, I really wish to diagnose and fix this issue for users

Okay, this was my initial config

"@octokit/core": "6.0.1"

tsconfig

{
  "compilerOptions": {
     "lib": [
        "es5",
        "es6"
     ],
     "target": "es5",
     "module": "commonjs",
     "moduleResolution": "node",
     "outDir": "./dist",
     "emitDecoratorMetadata": true,
     "experimentalDecorators": true,
     "sourceMap": true,
     "esModuleInterop": true,
  }
}```

@wolfy1339
Copy link
Member

wolfy1339 commented Mar 21, 2024

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

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

@iamnotstatic
Copy link

You are using CJS and not ESM. In typescript you can use ESM with CJS (though you can't mix ESM and CJS Octokit modules together due to upgraded dependencies introducing backwards incompatible changes) with the following options you should be fine

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

Alright thanks @wolfy1339

@JoaoScheleder
Copy link

@wolfy1339 I'm getting the same error and others, setting to ESM or "node16" in tsconfig
With:

"target": "es2016"
"module": "commonjs"

Results in:

[ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined

With:

"target": "es2022"
"module": "es2022"

Case package.json type = "module":

ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts".

Without package.json type = "module":

SyntaxError: Cannot use import statement outside a module and Cannot find module '@octokit/core'.

With:

"target": "es2022"
"module": "Node16"

Results in:

The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("@octokit/core")' call instead. To convert this file to an ECMAScript module, change its file extension to '.mts', or add the field "type": "module" to 'C:/Users/{user}/project/package.json'.

My default tsconfig.json file:

{
  "compilerOptions": {
    "target": "ES2016",                                  /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
    "module": "CommonJS",                                /* Specify what module code is generated. */
    "rootDir": "./",                                  /* Specify the root folder within your source files. */
    "outDir": "./dist",                                   /* Specify an output folder for all emitted files. */
    "esModuleInterop": true,                             /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
    "forceConsistentCasingInFileNames": true,            /* Ensure that casing is correct in imports. */    
    "strict": true,                                      /* Enable all strict type-checking options. */
    "skipLibCheck": true                                 /* Skip type checking all .d.ts files. */
  }
}

I'm using "@octokit/core": "^6.0.1" and Node v18.17.0
my import look like this:

import { Octokit } from "@octokit/core"
const octokit = new Octokit({ auth: env.GITHUB_TOKEN });

@wolfy1339
Copy link
Member

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: TypeStrong/ts-node#2094 TypeStrong/ts-node#2100

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

@jeremy-daley-kr
Copy link

jeremy-daley-kr commented Apr 4, 2024

@wolfy1339 I don't think this should've been closed out. The resolution would be to add to all octokit package.json files:

".": {
  "default": "path/to/entry.js"
}

So many packages I've seen in the wild omit default for some reason.

@wolfy1339
Copy link
Member

From how I interpret the documentation, default doesn't seem needed. It should match import
Even with the default, it would still error as it's ESM and people are trying to import it in a CJS environment.

Do you have an explanation as to why thus isn't the case?

@jeremy-daley-kr
Copy link

jeremy-daley-kr commented Apr 4, 2024

@wolfy1339 I've seen this happen in ts-node, tsx, and jest when packages don't include default. The technical reason of what those are all doing under the hood, I don't know precisely, but I also don't think it's always a trivial matter for someone to change a potentially very large project configuration. Is there a specific reason not to include a fallback? What led me here to begin with is seeing this issue with tsx after upgrading @octokit/core, and adding default allowed the resolution.

@JoaoScheleder @iamnotstatic @IchanZX1 @clementhemidy
This isn't a sustainable solution obviously, and once you fix one package.json, it will lead to the next @octokit package until they're all changed... but could you humor me, and add to ./node_modules/@octokit/core/package.json:

"exports": {
    ".": {
      "types": "./dist-types/index.d.ts",
-     "import": "./dist-src/index.js"
+     "import": "./dist-src/index.js",
+     "default": "./dist-src/index.js"
    }
  },

@JoaoScheleder
Copy link

JoaoScheleder commented Apr 4, 2024

@jeremy-daley-kr
I changed my package.json to type "module" and in my tsconfig i'm using:

"moduleResolution": "Node",
"module": "ES2022",
"target": "es2022", 

And it did help, but i was still getting an error.

Important

what helped me was switching from nodemon and ts-node to tsx.
my start script look like this:

"start": "npx tsx watch index.ts"

like @wolfy1339 said, ts-node has some bugs 👍

@wolfy1339
Copy link
Member

Is there a specific reason not to include a fallback? What led me here to begin with is seeing this issue with tsx after upgrading @octokit/core, and adding default allowed the resolution.

There isn't any specific reason. It's just how I have interpreted the specs. Feel free to send in PRs

wolfy1339 added a commit that referenced this issue Apr 8, 2024
wolfy1339 added a commit that referenced this issue Apr 9, 2024
* fix(pkg): add a default fallback

See #665 #667

* fix(pkg): add an export for `dist-types/types.d.ts`

Many people are importing from `dist-types/types.d.ts`, and the switch to ESM prevents them from using any of the types defined in that file.

* fix: mark `graphql` import as a type import

* docs: add note on needed config changes for TypeScript
wolfy1339 added a commit to octokit/plugin-paginate-rest.js that referenced this issue Apr 15, 2024
wolfy1339 added a commit to octokit/request-error.js that referenced this issue Apr 15, 2024
wolfy1339 added a commit to octokit/endpoint.js that referenced this issue Apr 15, 2024
wolfy1339 added a commit to octokit/plugin-rest-endpoint-methods.js that referenced this issue Apr 16, 2024
wolfy1339 added a commit to octokit/plugin-paginate-rest.js that referenced this issue Apr 16, 2024
* fix(pkg): add a default fallback

See ocotkit/core.js#665 octokit/core.js#667

* docs: add note on needed config changes for TypeScript

* fix(pkg): add an export for `dist-types/types.d.ts`
wolfy1339 added a commit to octokit/endpoint.js that referenced this issue Apr 16, 2024
* fix(pkg): add a `default` fallback export

See octokit/core.js#665 octokit/core.js#667

* docs(README): add note on needed config changes for TypeScript
wolfy1339 added a commit to octokit/request-error.js that referenced this issue Apr 16, 2024
* fix(pkg): add a default fallback

See octokit/core.js#665 octokit/core.js#667

* docs: add note on needed config changes for TypeScript
wolfy1339 added a commit to octokit/plugin-rest-endpoint-methods.js that referenced this issue Apr 16, 2024
* fix(pkg): add a `default` fallback export

See octokit/core.js#665 octokit/core.js#667

* docs: add note on needed config changes for TypeScript
idodod pushed a commit to earthly/actions-setup that referenced this issue Apr 18, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
|
[@octokit/plugin-paginate-rest](https://togithub.com/octokit/plugin-paginate-rest.js)
| [`11.1.0` ->
`11.1.1`](https://renovatebot.com/diffs/npm/@octokit%2fplugin-paginate-rest/11.1.0/11.1.1)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/@octokit%2fplugin-paginate-rest/11.1.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@octokit%2fplugin-paginate-rest/11.1.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@octokit%2fplugin-paginate-rest/11.1.0/11.1.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@octokit%2fplugin-paginate-rest/11.1.0/11.1.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>octokit/plugin-paginate-rest.js
(@&#8203;octokit/plugin-paginate-rest)</summary>

###
[`v11.1.1`](https://togithub.com/octokit/plugin-paginate-rest.js/releases/tag/v11.1.1)

[Compare
Source](https://togithub.com/octokit/plugin-paginate-rest.js/compare/v11.1.0...v11.1.1)

##### Bug Fixes

- **pkg:** add default fallback and types export
([#&#8203;612](https://togithub.com/octokit/plugin-paginate-rest.js/issues/612))
([069235f](https://togithub.com/octokit/plugin-paginate-rest.js/commit/069235f45a8b49f2bccdc9cc561ec7375d225eec)),
closes
[ocotkit/core.js#665](https://togithub.com/ocotkit/core.js/issues/665)
[octokit/core.js#667](https://togithub.com/octokit/core.js/issues/667)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 6am on monday" (UTC), Automerge
- At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/earthly/actions-setup).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zMDEuNCIsInVwZGF0ZWRJblZlciI6IjM3LjMwMS40IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJub24tbWFqb3IiLCJyZW5vdmF0ZSJdfQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
renovate bot added a commit to JoshuaKGoldberg/create-typescript-app that referenced this issue Apr 26, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
|
[@octokit/request-error](https://togithub.com/octokit/request-error.js)
| [`^6.0.0` ->
`^6.1.1`](https://renovatebot.com/diffs/npm/@octokit%2frequest-error/6.0.2/6.1.1)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/@octokit%2frequest-error/6.1.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@octokit%2frequest-error/6.1.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@octokit%2frequest-error/6.0.2/6.1.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@octokit%2frequest-error/6.0.2/6.1.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
| [octokit](https://togithub.com/octokit/octokit.js) | [`3.1.2` ->
`3.2.0`](https://renovatebot.com/diffs/npm/octokit/3.1.2/3.2.0) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/octokit/3.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/octokit/3.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/octokit/3.1.2/3.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/octokit/3.1.2/3.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>octokit/request-error.js
(@&#8203;octokit/request-error)</summary>

###
[`v6.1.1`](https://togithub.com/octokit/request-error.js/releases/tag/v6.1.1)

[Compare
Source](https://togithub.com/octokit/request-error.js/compare/v6.1.0...v6.1.1)

##### Bug Fixes

- **pkg:** add `default` fallback and `types` export
([#&#8203;419](https://togithub.com/octokit/request-error.js/issues/419))
([a1ab11e](https://togithub.com/octokit/request-error.js/commit/a1ab11e3d9bcc065bb0f5cb1c307d295aef85505)),
closes
[octokit/core.js#665](https://togithub.com/octokit/core.js/issues/665)
[octokit/core.js#667](https://togithub.com/octokit/core.js/issues/667)

###
[`v6.1.0`](https://togithub.com/octokit/request-error.js/releases/tag/v6.1.0)

[Compare
Source](https://togithub.com/octokit/request-error.js/compare/v6.0.3...v6.1.0)

##### Features

- **security:** Add provenance
([#&#8203;416](https://togithub.com/octokit/request-error.js/issues/416))
([2836ddb](https://togithub.com/octokit/request-error.js/commit/2836ddb477c1b9fc0310679017776d0ff8a009c6))

###
[`v6.0.3`](https://togithub.com/octokit/request-error.js/releases/tag/v6.0.3)

[Compare
Source](https://togithub.com/octokit/request-error.js/compare/v6.0.2...v6.0.3)

##### Bug Fixes

- **deps:** update dependency
[@&#8203;octokit/types](https://togithub.com/octokit/types) to v13
([352b655](https://togithub.com/octokit/request-error.js/commit/352b655b176d76c9c03649babaafd063227c3785))

</details>

<details>
<summary>octokit/octokit.js (octokit)</summary>

###
[`v3.2.0`](https://togithub.com/octokit/octokit.js/releases/tag/v3.2.0)

[Compare
Source](https://togithub.com/octokit/octokit.js/compare/v3.1.2...v3.2.0)

##### Features

- **security:** Add provenance
([#&#8203;2653](https://togithub.com/octokit/octokit.js/issues/2653))
([a90799a](https://togithub.com/octokit/octokit.js/commit/a90799a69cb0a62f9103b395c3f26627f0402755))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get
[config help](https://togithub.com/renovatebot/renovate/discussions) if
that's undesired.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/JoshuaKGoldberg/create-typescript-app).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zMjEuMiIsInVwZGF0ZWRJblZlciI6IjM3LjMyMS4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiXX0=-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment