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

Deploy analysis error when importing octokit/rest #8100

Open
larssn opened this issue Jan 6, 2025 · 3 comments
Open

Deploy analysis error when importing octokit/rest #8100

larssn opened this issue Jan 6, 2025 · 3 comments

Comments

@larssn
Copy link

larssn commented Jan 6, 2025

[REQUIRED] Environment info

firebase-tools: 13.29.1

Platform: macOS

[REQUIRED] Test case

Add import { Octokit } from '@octokit/rest' to your index.ts

[REQUIRED] Steps to reproduce

  • Create a new project.
  • Install Octokit: npm install @octokit/rest
  • Import it in your index.ts file: import { Octokit } from '@octokit/rest'
  • deploy it: firebase deploy --only functions

An error will be thrown:

FirebaseAppError: The default Firebase app already exists. This means you called initializeApp() more than once without providing an app name as the second argument. In most cases you only need to call initializeApp() once. But if you do want to initialize multiple apps, pass a second argument to initializeApp() to give each app a unique name.
    at AppStore.initializeApp (/Users/lars/workspace/tillty/tillty_cloud_functions/functions/node_modules/firebase-admin/lib/app/lifecycle.js:41:23)
    at initializeApp (/Users/lars/workspace/tillty/tillty_cloud_functions/functions/node_modules/firebase-admin/lib/app/lifecycle.js:102:36)
    at Object.<anonymous> (/Users/lars/workspace/tillty/tillty_cloud_functions/functions/src/index.ts:7:14)
    at Module._compile (node:internal/modules/cjs/loader:1358:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
    at Module.load (node:internal/modules/cjs/loader:1208:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1024:12)
    at cjsLoader (node:internal/modules/esm/translators:348:17)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:297:7)
    at ModuleJob.run (node:internal/modules/esm/module_job:222:25) {
  errorInfo: {
    code: 'app/duplicate-app',
    message: 'The default Firebase app already exists. This means you called initializeApp() more than once without providing an app name as the second argument. In most cases you only need to call initializeApp() once. But if you do want to initialize multiple apps, pass a second argument to initializeApp() to give each app a unique name.'
  },
  codePrefix: 'app'
}


Error: Functions codebase could not be analyzed successfully. It may have a syntax or runtime error

Now remove the import and try again.

It should deploy successfully.

[REQUIRED] Expected behavior

I expect Octokit to be usable.

[REQUIRED] Actual behavior

I think this is a false positive of the code analysis algorithm that runs before deployment.

@aalej
Copy link
Contributor

aalej commented Jan 7, 2025

Hey @larssn, thanks for the detailed report. I'm trying to replicate the error you mentioned using the steps provided, but so far no errors are being raised when running firebase deploy --only functions.

I created this repo using the information provided. The repo has a single https function that uses octokit/rest to return the details about a GitHub issue. In case I may be missing anything here, please let me know.

Also, looking up the error message, it seems like it's coming from firebase-admin. I'm not sure why this error is being raised when you import @octokit/rest and try to deploy, any chance you could share an MCVE or code snippets of the function you're trying to deploy to help us accurately reproduce the issue?

@aalej aalej added the Needs: Author Feedback Issues awaiting author feedback label Jan 7, 2025
@larssn
Copy link
Author

larssn commented Jan 7, 2025

Could it be that it's because octokit uses ES modules, and our project still uses CJS?

Using your repo, I manage to get it to output this error, after switching it to CJS:

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/lars/workspace/tillty/issues-8100/functions/node_modules/@octokit/rest/dist-src/index.js from /Users/lars/workspace/tillty/issues-8100/functions/lib/index.js not supported.
Instead change the require of /Users/lars/workspace/tillty/issues-8100/functions/node_modules/@octokit/rest/dist-src/index.js in /Users/lars/workspace/tillty/issues-8100/functions/lib/index.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/lars/workspace/tillty/issues-8100/functions/lib/index.js:9:16) {
  code: 'ERR_REQUIRE_ESM'
}

I wonder why the error in my project isn't like that though.

@google-oss-bot google-oss-bot added Needs: Attention and removed Needs: Author Feedback Issues awaiting author feedback labels Jan 7, 2025
@joehan
Copy link
Contributor

joehan commented Jan 7, 2025

Could you share a minimal repro or the code that is giving you this error? @aalej was able to deploy functions with Octokit imported, so I suspect this error is coming from somewhere else in the code (probably a repeat call to initializeApp())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants