payloadcms / payloadcms/payload

bin scripts always run in development mode (`process.env.NODE_ENV` is undefined)

Open
#14,428 2 comments 1 reaction 1 assignee View on GitHub

@paulpopus is already working on this.

Since Nov 3, 2025.

created-by: Contributor
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
  1. Checkout the linked reproduction app
  2. npm run build
  3. npm 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.