Skip to content

netlify deploy --build --prod runs with dev context #5875

Description

@lotarbo

Describe the bug

Hello, i think that when i run deploy command with --prod context should be production ?
Or context depends on git branch, etc?

ps:
I know that i can pass --context

Steps to reproduce

  1. create new branch ex: feature/netlify
  2. run netlify deploy --build --prod

Configuration

[build]
command = "npm run export && cp ./netlify-headers/_dev-headers ./out/_headers"
publish = "out"

[[headers]]
for = "/*"
[headers.values]
X-XSS-Protection = "1; mode=block"
X-Content-Type-Options = "nosniff"
Referrer-Policy = "no-referrer-when-downgrade"
Content-Security-Policy = "default-src 'self' http: https: ws: wss: data: blob: 'unsafe-inline'; frame-ancestors 'self';"
Permissions-Policy = "interest-cohort=()"
Strict-Transport-Security = "max-age=31536000; includeSubDomains; preload"

[context.production]
command = "npm run export"

Environment

System:
OS: macOS 13.4.1
CPU: (10) arm64 Apple M1 Pro
Memory: 790.27 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 16.18.0 - ~/.nvm/versions/node/v16.18.0/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v16.18.0/bin/yarn
npm: 9.3.1 - ~/.nvm/versions/node/v16.18.0/bin/npm
pnpm: 7.27.0 - ~/.nvm/versions/node/v16.18.0/bin/pnpm
npmPackages:
netlify-cli: ^15.9.0 => 15.9.0
npmGlobalPackages:
netlify-cli: 15.9.0

Activity

  1. lotarbo commented on Jul 18, 2023

    @lotarbo
    Author

    ​

    netlify deploy --build --prod
    
    Netlify Build
    ────────────────────────────────────────────────────────────────
     ​
    ❯ Version
      @netlify/build 29.16.1
     ​
    ❯ Flags
      {}
     ​
    ❯ Current directory
      /Users/lotarbo/0.work/site
     ​
    ❯ Config file
      /Users/lotarbo/0.work/site/netlify.toml
     ​
    ❯ Context
      dev
     ​
    build.command from netlify.toml
    ────────────────────────────────────────────────────────────────
     ​
    $ npm run export && cp ./netlify-headers/_dev-headers ./out/_headers
    
    
  2. added theissue type on Apr 23, 2025
  3. RealDoc06 commented on Nov 20, 2026

    @RealDoc06

    Note

    🤖 Claude Opus 5.5 responding on behalf of RealDoc06

    Fix is up in #11372.

    On current main, the build step itself already runs with production (@netlify/build defaults to CONTEXT || 'production'). What's still broken is the CLI's own config resolution: deploy --prod resolves netlify.toml with the dev context. As a result:

    • deploy --no-build --prod ignores [context.production] overrides (publish dir, functions, headers, redirects).
    • The deployed functions env is looked up from dev.

    #11372 makes --prod and --prod-if-unlocked default to production. An explicit --context or CONTEXT still wins. It includes unit tests for the precedence and a mock-API integration test that fails on main.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugcode to address defects in shipped code

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions