node.js - How can I use octokit with commonJs - Stack Overflow

admin2025-04-18  3

I am confused with how octokit is using imports. How can I use commonJs and not set the module and module resolution to Node16.

If I import the App like:

import {App} from "@octokit/app";

I get an error when deploying the firebase function:

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/andrewmainella/Desktop/Social-Activity-Functions/functions/node_modules/@octokit/app/dist-node/index.js from /Users/andrewmainella/Desktop/Social-Activity-Functions/functions/lib/index.js not supported. Instead change the require of /Users/andrewmainella/Desktop/Social-Activity-Functions/functions/node_modules/@octokit/app/dist-node/index.js in /Users/andrewmainella/Desktop/Social-Activity-Functions/functions/lib/index.js to a dynamic import() which is available in all CommonJS modules.

If I import the App like:

import {App} from "octokit";

I get multiple errors:

There are types at '/Users/andrewmainella/Desktop/Social-Activity-Functions/functions/node_modules/@octokit/core/dist-types/types.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.

Things that I have looked at and am confused about:

  1. .js?tab=readme-ov-file#usage, shows how to st up octokit. The problem is I am useing firebase functions which use commonjs. Octokit is not happy with this so do these things just not work together?

  2. Trying to import octokit directly and useing dynamic imports all face other errors.

Any help or direction would be appretiated.

I am confused with how octokit is using imports. How can I use commonJs and not set the module and module resolution to Node16.

If I import the App like:

import {App} from "@octokit/app";

I get an error when deploying the firebase function:

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/andrewmainella/Desktop/Social-Activity-Functions/functions/node_modules/@octokit/app/dist-node/index.js from /Users/andrewmainella/Desktop/Social-Activity-Functions/functions/lib/index.js not supported. Instead change the require of /Users/andrewmainella/Desktop/Social-Activity-Functions/functions/node_modules/@octokit/app/dist-node/index.js in /Users/andrewmainella/Desktop/Social-Activity-Functions/functions/lib/index.js to a dynamic import() which is available in all CommonJS modules.

If I import the App like:

import {App} from "octokit";

I get multiple errors:

There are types at '/Users/andrewmainella/Desktop/Social-Activity-Functions/functions/node_modules/@octokit/core/dist-types/types.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.

Things that I have looked at and am confused about:

  1. https://github.com/octokit/octokit.js?tab=readme-ov-file#usage, shows how to st up octokit. The problem is I am useing firebase functions which use commonjs. Octokit is not happy with this so do these things just not work together?

  2. Trying to import octokit directly and useing dynamic imports all face other errors.

Any help or direction would be appretiated.

Share Improve this question edited Jan 30 at 13:47 Doug Stevenson 319k36 gold badges456 silver badges473 bronze badges Recognized by Google Cloud Collective asked Jan 30 at 9:35 Andrew MainellaAndrew Mainella 411 silver badge3 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I made a rookie mistake. ESM modules should have a package.json with "type": "module". Also, the eslint file needs to have a cjs extension in ESM. This as well as making changes to the tsconfig will allow the build to deploy correctly to cloud run!

转载请注明原文地址:http://anycun.com/QandA/1744928756a89619.html