payloadcms / payloadcms/payload
bin scripts always run in development mode (`process.env.NODE_ENV` is undefined)
@paulpopus is already working on this.
Since Nov 3, 2025.
- Dominant language
- TypeScript
- Stars
- 44.8k
- Forks
- 4.2k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 53
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.