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]: Neither apiKey nor config.authenticator provided #667

Closed
yafkari opened this issue Oct 13, 2024 · 23 comments
Closed

[BUG]: Neither apiKey nor config.authenticator provided #667

yafkari opened this issue Oct 13, 2024 · 23 comments
Labels
bug Something isn't working

Comments

@yafkari
Copy link

yafkari commented Oct 13, 2024

What happened?

Upgrading to 4.8.0 makes calling loadStripe to crash giving the error "Neither apiKey nor config.authenticator provided"

Please have a look at stripe/stripe-node#2207

Environment

No response

Reproduction

No response

@yafkari yafkari added the bug Something isn't working label Oct 13, 2024
@berenar
Copy link

berenar commented Oct 14, 2024

Same here

@Brakkar
Copy link

Brakkar commented Oct 14, 2024

Same here with node stripe 17.2.0 , on a firebase cloud function code. I'm NOT using NextJs at all.

@bclayton21
Copy link

Same here, I'm also experiencing this while using firebase cloud functions.

@WissemF123
Copy link

Do you find the solution ? Because I have the same error

@brendanm-stripe
Copy link
Contributor

Doe anyone have an example/reproduction they can share?

@bclayton21 can you say more about how this work? I don't understand how you'd be loading/using Stripe.js in this context.

@Brakkar
Copy link

Brakkar commented Oct 16, 2024

See if this solution helps:
https://stackoverflow.com/questions/79086035/firebase-deploy-error-neither-apikey-nor-config-authenticator-provided-using-s/

@brendanm-stripe
Copy link
Contributor

Are any of you having this issue with this package specifically? @stripe/stripe-js and NOT stripe-node aka stripe NPM package?

@yafkari you mentioned loadStripe which would be from this library. Can you share more about how you're using loadStripe? Are you also providing the PK via an environment variable? This all sounds like something has change with the way environment variables are loaded/initialized, so I would suggest trying first with a hard-coded key, then check your env var key is populated like you expect. If its not, you'll need to investigate why that is.

@yafkari
Copy link
Author

yafkari commented Oct 16, 2024

Hey @brendanm-stripe , thanks for looking into this.

Indeed, I pass env variables to loadStripe. I've put screenshots on my comment here: stripe/stripe-node#2207 (comment)

Should have copied them in the issue, my bad.

@brendanm-stripe
Copy link
Contributor

At the time you call loadStripe are you sure the environment variable has the value you expect? Do you have the same problem if you put your PK in as a string constant?

@abyssbandit97
Copy link

function createStripeInstance() {
const stripe = require('stripe')(process.env.STRIPE_SECRET);
return stripe;
}
module.exports = createStripeInstance;

i put this code in a utils/stripe.js file and i get this error: Uncaught Error Error: Neither apiKey nor config.authenticator provided

If I don't use it, I get undefined

@brendanm-stripe
Copy link
Contributor

What is your environment @abyssbandit97 ? Does providing the key as a string constant (not an environment variable) resolve the error?

@WissemF123
Copy link

@brendanm-stripe that is my file :
import Stripe from "stripe";

export const stripe = new Stripe(process.env.STRIPE_SECRET_KEY ?? "", {
apiVersion: "2024-09-30.acacia",
typescript: true,
});
And I get the same error

@maiconsanson
Copy link

maiconsanson commented Oct 19, 2024

I had the same problem (production only) after the following package updates:

from "stripe": "16.12.0" to "stripe": "17.2.1"
from "@stripe/stripe-js": "4.7.0" to "@stripe/stripe-js": "4.8.0"

After a rollback, the error disappears.

@Yohannfra
Copy link

I have the same issue when building for production. I'm rolling back to 16.12.0 for now

@brendanm-stripe
Copy link
Contributor

@WissemF123 That import 'stripe'; is a stripe-node import, not this package (Stripe.js loader module).

Similarly, @Yohannfra this module is currently as v4.8.0. The v16.x/v17.x module must also be stripe-node, not this module.

@abyssbandit97
Copy link

What is your environment @abyssbandit97 ? Does providing the key as a string constant (not an environment variable) resolve the error?

It doesn't. I couldn't even see my secret_key when I displayed to the console. but it shows now require('dotenv').config(); const stripe = require('stripe')(process.env.STRIPE_SECRET); this code sits comes first in my route script. that works fine, but I still get a stripe is not defined error after I put my cards and try to execute payment

@brendanm-stripe
Copy link
Contributor

It doesn't. I couldn't even see my secret_key when I displayed to the console. but it shows now require('dotenv').config(); const stripe = require('stripe')(process.env.STRIPE_SECRET); this code sits comes first in my route script. that works fine, but I still get a stripe is not defined error after I put my cards and try to execute payment

const stripe = require('stripe')(process.env.STRIPE_SECRET);

@abyssbandit97 This is initialization code for stripe-node (the server SDK), not this module which is @stripe/stripe-js (for loading Stripe.js & Elements).

This error is only thrown from within stripe-node: https://github.com/stripe/stripe-node/blob/v17.2.0/src/stripe.core.ts#L241-L243

@Megaemce
Copy link

I managed to fix this issue by moving my Stripe instance initialization from the top of the file to the POST request body, like this:

{35C26C90-6D7A-4451-A536-218FE476CC54}

@Brakkar
Copy link

Brakkar commented Oct 22, 2024

I managed to fix this issue by moving my Stripe instance initialization from the top of the file to the POST request body, like this:

This is the fix I posted in my stackoverflow link from above:

https://stackoverflow.com/questions/79086035/firebase-deploy-error-neither-apikey-nor-config-authenticator-provided-using-s/

@brendanm-stripe
Copy link
Contributor

Based on the code path that throws this error and the examples I've seen so far, I am closing this as confusion around @stripe/stripe-js (this module) vs stripe (stripe-node) on NPM.

@cagarweyne
Copy link

From reading the responses here I couldn't see what the fix was? I am using the stripe node package stripe-node and I get this error on version 17.2.1. I am using like this

import Stripe from 'stripe';

export const key =
  process.env.NODE_ENV === 'production'
    ? process.env.STRIPE_SECRET_KEY_LIVE
    : process.env.STRIPE_SECRET_KEY_TEST;

const stripe = new Stripe(key as string, {
  apiVersion: '2024-09-30.acacia',
});

export default stripe;

It was working fine before upgrading to this version.

@brendanm-stripe
Copy link
Contributor

brendanm-stripe commented Oct 30, 2024

@cagarweyne 'stripe' is a different package for the Node.js server SDK. This repo is for @stripe/stripe-js -- the module loader for Stripe.js client side. Please refer to the linked issue in the stripe-node repo.

@cagarweyne
Copy link

Sorry my mistake - thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests