Skip to content

fix: support @next/env without default export on Next.js 15.5+#16675

Open
rachit367 wants to merge 1 commit into
payloadcms:mainfrom
rachit367:fix-loadenv-nextjs-155-default-export
Open

fix: support @next/env without default export on Next.js 15.5+#16675
rachit367 wants to merge 1 commit into
payloadcms:mainfrom
rachit367:fix-loadenv-nextjs-155-default-export

Conversation

@rachit367
Copy link
Copy Markdown

Fixes #16674.

On Next.js 15.5+, @next/env no longer ships a default export — only named exports remain. bin/loadEnv.ts does import nextEnvImport from '@next/env' and then const { loadEnvConfig } = nextEnvImport, which throws TypeError: Cannot destructure property 'loadEnvConfig' of 'import_env.default' as it is undefined. whenever the module is loaded through interop paths (e.g. running scripts via tsx).

Switching to a namespace import and falling back from .default to the namespace itself keeps both shapes working:

  • Next.js ≥ 15.5: nextEnvImport.default is undefined, so we destructure from the namespace.
  • Next.js < 15.5: nextEnvImport.default is the legacy CJS default object, so we destructure from that (matches the previous behaviour).

The patch is exactly what the issue proposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

loadEnv fails with "Cannot destructure property 'loadEnvConfig'" on Next.js 15.5+

1 participant