Next.js warns that next.config.js is invalid
warning Invalid next.config.jsShort answer
The warning means next.config holds an option that is the wrong type, misspelled, or removed in your Next.js version. Type the config with NextConfig so the editor flags it, then move renamed keys: serverComponentsExternalPackages, experimental.turbo, and remove eslint, amp and runtime config options.
Fix it fast
1Find out which cause you have
Add the NextConfig type to the file. Your editor then marks the option Next.js does not accept.
// next.config.ts import type { NextConfig } from 'next' const nextConfig: NextConfig = { /* options */ } export default nextConfig2Match what you see, then jump to its fix
- 1
The unknown key is under experimental, such as serverComponentsExternalPackages or bundlePagesExternalsAn experimental option was promoted and renamed (Next.js 15)Fix - 2
The key is experimental.turbo, eslint, amp, serverRuntimeConfig or publicRuntimeConfigAn option was moved or removed in Next.js 16Fix - 3
Options are ignored although the file looks correctThe config file has a name or format Next.js does not loadFix
- 1
What does the error look like?
warning Invalid next.config.jsInvalid next.config.js
Cause 1 of 3
An experimental option was promoted and renamed (Next.js 15)
1Check
Search the config for the old names.
grep -n "serverComponentsExternalPackages\|bundlePagesExternals" next.config.*2Fix
Use the stable names at the top level of the config.
const nextConfig = {
serverExternalPackages: ['package-name'],
bundlePagesRouterDependencies: true,
}
module.exports = nextConfig3Verify
Start the app again; the warning should be gone.
npx next devConfirmed by nextjs.org
Cause 2 of 3
An option was moved or removed in Next.js 16
1Check
Compare your keys with the Next.js 16 list. experimental.turbo moved to a top-level turbopack key. The eslint option, the amp config and the runtime config options were removed.
grep -n "turbo\|eslint\|amp\|RuntimeConfig" next.config.*2Fix
Move turbo to turbopack, delete the removed keys, and use environment variables instead of runtime config. Run ESLint through its own CLI.
const nextConfig = {
turbopack: {
// options
},
}
module.exports = nextConfig3Verify
Run the build and read the first lines of output.
npx next buildConfirmed by nextjs.org
Cause 3 of 3
The config file has a name or format Next.js does not load
1Check
Supported names are next.config.js, next.config.mjs and next.config.ts. A .cjs or .cts extension is not supported. Use export default in .mjs and .ts files, and module.exports in .js.
ls next.config.*2Fix
Rename the file to a supported name and match the export style to the extension.
mv next.config.cjs next.config.js3Verify
Restart the dev server.
npx next devConfirmed by nextjs.org
How do I stop it coming back?
- Type the config with NextConfig so a bad key fails in the editor, not in the terminal.
- Read the upgrade guide for each major version before bumping next.
- Run the official upgrade codemod, which updates renamed options for you.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Web apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
Clerk cannot read its publishable key in a Next.js app
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY is undefined
Clerk reads NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY.
3 causes, each with a fixWeb apps
The shell cannot find create-next-app
command not found: create-next-app
create-next-app is not meant to be installed as a shell command.
2 causes, each with a fixWeb apps
ESLint fails with: Cannot find module 'next/babel'
ESLint stops on the first file with a Babel or parser error instead of listing lint results
next/babel is a Babel preset that ships inside the next package.
3 causes, each with a fixWeb apps
Firebase Auth says the API key is not valid
Firebase: Error (auth/api-key-not-valid.-please-pass-a-valid-api-key.)
The apiKey your app sends is either empty, wrong, or blocked.
4 causes, each with a fixWeb apps
Jest fails with SyntaxError: Unexpected token when testing a Next.js component
Jest failed to parse a file.
Jest only understands plain JavaScript until a transform and a few file mappings tell it more.
3 causes, each with a fix