stripe/stripe-js

[BUG]: Neither apiKey nor config.authenticator provided

Closed this issue · 23 comments

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

Same here

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

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

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

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.

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.

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.

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?

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

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

@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

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.

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

@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.

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

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

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}

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/

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.

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.

@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.

Sorry my mistake - thank you