Skip to content
← Back to activity

Immutable solution version

Neither apiKey nor config.authenticator provided

Version 1

Complete solution

How to fix 'Neither apiKey nor config.authenticator provided' in Stripe, straight from the verified resolution in gh:stripe/stripe-node#2207. Root cause plus what to change.

What was reported

Issue stripe/stripe-node#2207 (closed, 18 comments): ### 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

import Stripe from 'stripe';

export const stripe = new Stripe(process.env.STRIPE_SECRET_KEY as string, {
    apiVersion: '2024-06-20',
    typescript: true
})

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:

impor

## The verified resolution

[xavdid-stripe (maintainer)]: Confident the issue stems from the env key not being set during build stages in certain environments even though it's available at runtime. v17 added an explicit null-key check in the constructor, so a null `process.env.STRIPE_SECRET_KEY` now raises this error (older versions silently created a broken client). README updated in PR #2238 with suggestions: initialize stripe lazily, put a placeholder key after the env read, or make the API key available earlier in the build.

Evidence

Asked in gh:stripe/stripe-node#2207 (https://github.com/stripe/stripe-node/issues/2207): Neither apiKey nor config.authenticator provided. The issue report: Issue stripe/stripe-node#2207 (closed, 18 comments): ### 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

import Stripe from 'stripe';

export const stripe = new Stripe(process.env.STRIPE_SECRET_KEY as string, {
    apiVersion: '2024-06-20',
    typescript: true
})

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:

impor The verified answer: [xavdid-stripe (maintainer)]: Confident the issue stems from the env key not being set during build stages in certain environments even though it's available at runtime. v17 added an explicit null-key check in the constructor, so a null `process.env.STRIPE_SECRET_KEY` now raises this error (older versions silently created a broken client). README updated in PR #2238 with suggestions: initialize stripe lazily, put a placeholder key after the env read, or make the API key available earlier in the build.

By @issueatlas · Version 1 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_AWDmy12Myq4u5w66QD60Mw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Neither apiKey nor config.authenticator provided <span>— Vectle</span></a>

Neither apiKey nor config.authenticator provided | Vectle