-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
Describe the Bug
Bin scripts appear to always be run in development mode - more specifically, process.env.NODE_ENV is undefined.
Running npm run payload test-node-env as described in the reproduction steps prints:
$ npm run payload test-node-env
> bin-scripts-node-env@1.0.0 payload
> cross-env NODE_OPTIONS=--no-deprecation payload test-node-env
process.env.NODE_ENV = undefined
process.env.CUSTOM_VAR = dev
This can have unexpected consequences. For example, db push is disabled for a production server running with Postgres or SQLite. If a bin script that modifies the database is run, it may try to push dev schema changes to the production database and lead to errors. (This was the case that lead me to investigate this issue.)
A workaround is to set NODE_ENV when running the bin script:
$ NODE_ENV=production npm run payload test-node-env
> bin-scripts-node-env@1.0.0 payload
> cross-env NODE_OPTIONS=--no-deprecation payload test-node-env
process.env.NODE_ENV = production
process.env.CUSTOM_VAR = prod
I don't find this obvious or desirable however as I would expect Payload/Next.js to manage the value of NODE_ENV.
Link to the code that reproduces this issue
https://github.com/jefferyto/payload-bin-scripts-node-env
Reproduction Steps
- Checkout the linked reproduction app
npm run buildnpm run payload test-node-env
Which area(s) are affected? (Select all that apply)
Not sure
Environment Info
Binaries:
Node: 22.21.1
npm: 11.6.2
Yarn: N/A
pnpm: N/A
Relevant Packages:
payload: 3.62.0
next: 15.4.4
@payloadcms/db-sqlite: 3.62.0
@payloadcms/drizzle: 3.62.0
@payloadcms/email-nodemailer: 3.62.0
@payloadcms/graphql: 3.62.0
@payloadcms/next/utilities: 3.62.0
@payloadcms/payload-cloud: 3.62.0
@payloadcms/richtext-lexical: 3.62.0
@payloadcms/translations: 3.62.0
@payloadcms/ui/shared: 3.62.0
react: 19.1.0
react-dom: 19.1.0
Operating System:
Platform: linux
Arch: x64
Version: #35-Ubuntu SMP PREEMPT_DYNAMIC Sat Oct 11 10:06:31 UTC 2025
Available memory (MB): 7225
Available CPU cores: 4