Comments (24)
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
from core.js.
You are using CJS and not ESM. You will need to use dynamic imports or upgrade to ESM
"target": "es2022",
"module": "node16",
"moduleResolution": "node16",
from core.js.
👋 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! 🚀
from core.js.
Please share reproducible code example
from core.js.
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
from core.js.
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";
from core.js.
Are you using typescript at all? In typescript just because you are importing using ESM imports doesn't mean you are using ESM
from core.js.
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
from core.js.
Anyone found a workaround for this, i'm also experiencing same issue
from core.js.
Anyone found a workaround for this, i'm also experiencing same issue
@iamnotstatic Please read my comment above.
Please provide all relevant information
from core.js.
@wolfy1339 https://github.com/Darker935/MdgWa-TEST
Run with npm run dev
from core.js.
@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
from core.js.
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
from core.js.
I understand that downgrading has solved the issue, I really wish to diagnose and fix this issue for users
from core.js.
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,
}
}```
from core.js.
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
from core.js.
@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 });
from core.js.
@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.
from core.js.
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?
from core.js.
@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"
}
},
from core.js.
@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 👍
from core.js.
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 addingdefault
allowed the resolution.
There isn't any specific reason. It's just how I have interpreted the specs. Feel free to send in PRs
from core.js.
🎉 This issue has been resolved in version 6.1.2 🎉
The release is available on:
Your semantic-release bot 📦🚀
from core.js.
I just released a new version with the fix as described by @jeremy-daley-kr
Please open up a new issue if you still have issues.
from core.js.
Related Issues (20)
- [BUG]: Uncaught ReferenceError: global is not defined HOT 7
- [BUG]: octokit.graphql gives increasing number of duplicate HOT 1
- [BUG]: can not intercept requests with nock HOT 2
- [BUG]: Octokit version 4.2.2 has a breaking change dependency upgrade HOT 2
- https://github.com/ietf-tools/datatracker/commit/e68b9cf60c0f6771e40ed73a4f59aa47cacbb854
- Re-enable tests in `@octokit/core` using fetch dispatchers HOT 2
- Avoid JSON.stringify hack when testing responses of fetch-mock HOT 7
- Replace `toStrictEqual` with `JSON.stringify` Response assertions with `toEqual` in `core.js` HOT 1
- [BUG]: Unexpected token '{' in Safari pre 16.3 HOT 4
- [BUG]: Rest call to delete comment returns 404 HOT 3
- [MAINT]: Replace lolex with @sinon/fake-timers HOT 2
- [BUG]: OctokitOptions declared locally but not exported HOT 7
- [QUESTION] Is there an alternative version of this project written in c#? HOT 2
- [BUG]: The type of 'data' field in OctokitResponse type is an object but type hinting show it's an array HOT 2
- [BUG]: Commit not found when it exists HOT 2
- [BUG]: `No "exports" main defined` in version 6.0.1 HOT 5
- [BUG/ASK for HELP]: Issues with `@octokit/[email protected]+` when using `ncc` to bundle code HOT 6
- 👋 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](https://github.com/octokit/.github/blob/main/community/prioritization_response.md#overview) 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! 🚀 HOT 1
- [BUG]: Headers from API endpoint does not contain a link header HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from core.js.