-
Notifications
You must be signed in to change notification settings - Fork 756
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
Neither apiKey nor config.authenticator provided #2207
Comments
I have the same error when switching from stripe 16.12.0 to 17.2.0. (I'm also using NextJS 14) The issue occurs in my case when calling "loadStripe" from a client component with stripe-js (4.8.0) My env variables are of course set up, and everything was working before upgrading anyway. For now it prevents me from upgrading to the newest version since it crashes my page. EDIT: Indeed, the issue was coming from stripe-js 4.8.0. Donwgraded to 4.7.0 fixed the issue EDIT2: Or not actually |
I also have this problem. It only happens when getting the key from environement data. When I hardcore the key as string it works ok. I'm NOT using NextJS: it happens when deploying firebase cloud function code. |
✅ I was able to fix by downgrading (Next.js 14 issues) npm uninstall stripe
npm install stripe@^16.9.0 // lib/stripe.js (WORKING)
import Stripe from 'stripe'; // v16.9.0
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY, {
// https://github.com/stripe/stripe-node#configuration
apiVersion: '2024-06-20',
appInfo: {
name: 'store-name',
url: process.env.PUBLIC_URL as string,
},
}); ErrorWhen using
error: // lib/stripe.js (FAILING)
import Stripe from 'stripe'; // v17.2.0
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY, {
// https://github.com/stripe/stripe-node#configuration
apiVersion: '2024-09-30.acacia',
appInfo: {
name: 'store-name',
url: process.env.PUBLIC_URL,
},
}); |
@Brakkar I'm experiencing a similar issue to you (ie. when deploying firebase functions) except that the error occurs when building my functions in Github Actions using vite and Node 18.x. Do you have a similar setup? |
Stripe env vars aren't available at build time. stripe/stripe-node#2207
Hey everyone, I'm reopening this issue for investigation. Can someone send me a small example project that shows the issue? Something I can set up and run to see the issue quickly, with without stripe-js as a dependency, would be an ideal. Or, steps to create one such project would work too. Thanks! |
In my case, I was using nextjs and I fixed the issue by splitting a file containing Stripe types that was import in both server and client code. The initiation of Stripe was in that file. I now have a separated file for
|
@yafkari Thanks for the update! Just to make sure I understand: you had a common file that is included in both client and server code, that also contained this Stripe initialization and that was raising this error; your fix was to refactor the Stripe initialization into a separate I did a bit of investigation here and tried to run thru the steps to reproduce, and the only way I could get that error was if my environment variable for key was null. Prior to v17, passing a null key into the Stripe constructor would succeed but would create a Stripe object with invalid auth. After v17, it raises this error (see stripe-node/src/stripe.core.ts Line 241 in d12717a
new Stripe(...) is called, the key secret key environment variable is not initialized, but it's called again with an initialized variable before you ever make a call to Stripe. Or something to that effect.
For anyone here who is still having trouble here, could you try a quick experiment? Update to v17 and add a line right before the call to
(replace STRIPE_SECRET_KEY with your secret key variable). Let me know if that error gets hit; I think that will confirm my suspicion or give me a good place to continue investigating. Thanks all for your patience while we figure this out! |
@jar-stripe Also running into this issue. I'm running Next.js 14.2.5, this is happening whenever the app is built. I experimented with what you suggested, like so:
This logs the "no key" error, when building from a Dockerfile. Works fine when building normally through next.js, the error shows up right after the app is compiled successfully and next.js begins "Linting and checking validity of types ..." Hard-coding the NEXT_PRIVATE_STRIPE_API_KEY env variable fixes the issue. For now I'm going to downgrade the sdk version to what was previously working. |
Thanks @juanpablofernandez ! Unfortunately, this doesn't sound like an SDK issue per se; if "no key" is getting logged, that means that your api key is null that first time its being passed into Thanks again! |
@jar-stripe sure I'll share the Dockerfile in a bit. But just a heads up, this only started happening after I updated the sdk to the latest version. |
Thanks @juanpablofernandez , I hear ya. In v17 of the SDK, we did add an explicit check for a null key inside the constructor: stripe-node/src/stripe.core.ts Line 241 in d12717a
That check did not exist before, but it wasn't really "working" in the old SDK; just not raising the error when a null key is passed in. null is not a valid key to |
Yeah, that makes sense @jar-stripe , I was just re-reading your comment for that. I'm guessing that's why on older SDK versions, when building without the .env, it would succeed and cause no further issues since the .env was passed down at runtime (through docker compose in my case). Based on the above, I was able to fix the issue by passing in an API key placeholder which is only used at build-time, like so:
|
@juanpablofernandez Thanks for the note and the workaround! Your explanation about the .env not being there at build time makes sense, and I can definitely see how that would cause this issue. No rush but whenever you can, please send that Dockerfile and I can add a ticket on our end to look at improving this experience. |
Describe the bug
When installing either the version 17.0.0 or 17.1.0
in a brand new next.js 14 from scratch after initializing stripe
I get the following error: Neither apiKey nor config.authenticator provided
This issue is not seen after downgrading to 16.12.0
To Reproduce
Create a next.js project
adding stripe version 17.1.0
add a lib folder with a new file stripe.ts
with the following:
run the project
getting this error: Neither apiKey nor config.authenticator provided
Expected behavior
No error should be seen in either version 17.1.0 and 17.0.0
process.env.STRIPE_SECRET_KEY is well-defined, and I can console.log it value.
Code snippets
No response
OS
macos
Node version
v20.11.0
Library version
v17.1.0
API version
2024-09-30.acacia
Additional context
No response
The text was updated successfully, but these errors were encountered: