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

admin.credential.cert Invalid or unexpected token #2276

Open
folmosr opened this issue Aug 7, 2023 · 10 comments
Open

admin.credential.cert Invalid or unexpected token #2276

folmosr opened this issue Aug 7, 2023 · 10 comments
Assignees

Comments

@folmosr
Copy link

folmosr commented Aug 7, 2023

I took this package to the latest version 11.10.1, I always use this variation to connect to the database

admin.initializeApp({ credential: admin.credential.cert({ 'projectId': '----', 'privateKey': '-----BEGIN PRIVATE KEY-----\n....\n-----END PRIVATE KEY-----\n', 'clientEmail': '[email protected]', }), databaseURL: https://pickapp-cl-qa-279013.firebaseio.com`,
});`

but now It's throwing this exception

const initialSettings = this.firestoreSettings.get(databaseId) ?? {}; SyntaxError: Invalid or unexpected token at Object.Module._extensions..js (node:internal/modules/cjs/loader:1250:10)

I have tested this from version 11.3.0 and below and it works as expected

@google-oss-bot
Copy link

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

@lahirumaramba
Copy link
Member

Hey @tom-andersen this could be related to the multidb feature. Could you take a look when you have a moment? Thanks!

@lahirumaramba
Copy link
Member

Hey @folmosr what version of @google-cloud/firestore dependency are you using in your project? Could you try upgrading @google-cloud/firestore to 6.7.0 and see if that solves the issue? Thanks!

@folmosr
Copy link
Author

folmosr commented Aug 22, 2023

Hey @lahirumaramba , I'm using these 2 packages

@firebase/firestore 4.0.0,
firebase-admin 11.0.0

I've taken @firebase/firestore to version 4.1.1 but I'm still having the same issue

@tom-andersen
Copy link
Contributor

Hey @lahirumaramba. The problem looks to be related to parsing the following line:

const initialSettings = this.firestoreSettings.get(databaseId) ?? {};

This might have something to do with the version of NodeJS. the ``??` operator requires v14 or higher.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing#browser_compatibility

@folmosr
Copy link
Author

folmosr commented Sep 5, 2023

In my Docker file I'm using node:18-alpine and locally Node v16.20.0

@folmosr
Copy link
Author

folmosr commented Sep 29, 2023

Hey @folmosr what version of @google-cloud/firestore dependency are you using in your project? Could you try upgrading @google-cloud/firestore to 6.7.0 and see if that solves the issue? Thanks!

Hey @lahirumaramba I tested this packed but I ended up getting the same result, now I can see there is a new version of firebase-admin, I'll test this version and I will let you know how it goes, thanks.

@gregfenton
Copy link

gregfenton commented Feb 23, 2024

I am having the same issue when I go to use any Admin SDK function after initializing with a service account. Code works fine with v10.3.0 but fails with all v11 and v12 that I have tried.

The same issue is detailed in this SO post, including my comments from today.

With v11.11.1 I get this exception:

/Users/greg/work/prod/tick8s/node_modules/firebase-admin/lib/auth/base-auth.js:421
        if (properties?.providerToLink) {
                       ^

SyntaxError: Invalid or unexpected token
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)

Note I am running my code as ESM yet I see the error above mentions /cjs/

UPDATE

This seems to be an ESM vs CJS issue. My code runs as ESM (it is an older codebase using node -r esm ...) and the stack trace here and in the OP indicates node:internal/modules/cjs/loader.

Trying to build a repro is proving challenging....the issue goes away with a clean codebase and nice/proper handling of ESM. The code works fine with v10, v11 and v12 in this configuration.

@iaroslav-ianishyn
Copy link

I am having the same issue when I go to use any Admin SDK function after initializing with a service account. Code works fine with v10.3.0 but fails with all v11 and v12 that I have tried.

The same issue is detailed in this SO post, including my comments from today.

With v11.11.1 I get this exception:

/Users/greg/work/prod/tick8s/node_modules/firebase-admin/lib/auth/base-auth.js:421
        if (properties?.providerToLink) {
                       ^

SyntaxError: Invalid or unexpected token
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)

Note I am running my code as ESM yet I see the error above mentions /cjs/

UPDATE

This seems to be an ESM vs CJS issue. My code runs as ESM (it is an older codebase using node -r esm ...) and the stack trace here and in the OP indicates node:internal/modules/cjs/loader.

Trying to build a repro is proving challenging....the issue goes away with a clean codebase and nice/proper handling of ESM. The code works fine with v10, v11 and v12 in this configuration.

Hello! I have absolutely the same issue.
Could you please give more details on "the issue goes away with a clean codebase and nice/proper handling of ESM".
I can't understand where to start to dig at all.
Downgrading firebase-admin version is not an option now :(

@gregfenton
Copy link

@iaroslav-ianishyn by "ESM" I mean that my code base is now using "type: module" in package.json and all my code uses ESM syntax (e.g. import instead of require(), etc.)

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

6 participants