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]: require("@octokit/auth-app"); Error [ERR_REQUIRE_ESM]: require() of ES Module #624

Closed
1 task done
gfrid opened this issue Jul 3, 2024 · 6 comments
Closed
1 task done
Labels
Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented, or is being fixed

Comments

@gfrid
Copy link

gfrid commented Jul 3, 2024

What happened?

require("@octokit/auth-app"); cant work with NestJS

Versions

node: v20.10.0
nest: 10.4.1

Relevant log output

const auth_app_1 = require("@octokit/auth-app");
                   ^
Error [ERR_REQUIRE_ESM]: require() of ES Module C:\GitHub\auth\hello-world\node_modules\@octokit\auth-app\dist-node\index.js from C:\GitHub\auth\hello-world\dist\app.service.js not supported.
Instead change the require of index.js in C:\GitHub\auth\hello-world\dist\app.service.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (C:\GitHub\auth\hello-world\dist\app.service.js:11:20)

Code of Conduct

  • I agree to follow this project's Code of Conduct
@gfrid gfrid added Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented, or is being fixed labels Jul 3, 2024
Copy link
Contributor

github-actions bot commented Jul 3, 2024

👋 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 labeled 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

This is not a bug. We switched to ESM

@wolfy1339 wolfy1339 closed this as not planned Won't fix, can't repro, duplicate, stale Jul 3, 2024
@gr2m
Copy link
Contributor

gr2m commented Jul 3, 2024

You can use the last version supporting CJS which currently is 6.1.1. We can still accept bug fixes and will apply security fixes to 6.x, but we do recommend to upgrade to ESM, as we won't add more features to 6.x

@gfrid
Copy link
Author

gfrid commented Jul 3, 2024

so apperantly the ESM community does not want to deal with commonjs and Nest community don't want to deal with ESM, they both argue a lot on github community but i came with solution:

tsconfig:

{
  "compilerOptions": {
    "module": "Node16", << --- Using await import() with moduleResolution set to nodenext or node16
    "esModuleInterop": true,
    "target": "ESNext",
    "moduleResolution": "node16", <--- Using await import() with moduleResolution set to nodenext or node16
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "sourceMap": true,
    "declaration": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  },
  "include": ["src/**/*.ts"],
  "exclude": ["node_modules"]
}

import { Injectable } from '@nestjs/common';

@Injectable()
export class AppService {
  async getHello(): Promise<string> {
    const { createAppAuth } = await import('@octokit/auth-app');
    const { Octokit } = await import('@octokit/rest');```

@gfrid
Copy link
Author

gfrid commented Jul 3, 2024

You can use the last version supporting CJS which currently is 6.1.1. We can still accept bug fixes and will apply security fixes to 6.x, but we do recommend to upgrade to ESM, as we won't add more features to 6.x

Nest dont want to support ESM, people in their community leaving :) LOL

@gr2m
Copy link
Contributor

gr2m commented Jul 3, 2024

I heard Fastify is great 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented, or is being fixed
Projects
Archived in project
Development

No branches or pull requests

3 participants