Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Setting NODE_ENV=production fails without payload:build

default discord avatar
mryellow10 months ago
1 4

Link to reproduction

No response

Describe the Bug

When setting NODE_ENV=production on a plain Javascript build the admin interface fails to load on /admin.

I believe it could be that the changes to defaults when process.env.NODE_ENV === 'production'.

Saw mention of default base directory changing when NODE_ENV is set to production though struggle to find that documentation again.

To Reproduce

  • Place Javascript version of the files in /dist
  • Run cross-env PAYLOAD_CONFIG_PATH=dist/payload.config.js NODE_ENV=production node dist/server.js

Payload Version

2

Adapters and Plugins

No response

  • Selected Answer
    default discord avatar
    mryellow9 months ago

    There should be a descriptive error.

    1 reply
  • default discord avatar
    mryellow9 months ago
  • default discord avatar
    mryellow10 months ago

    The failure of the admin interface to be accessible may relate to this section taking a different path in the builder:

    if (process.env.NODE_ENV === 'production') {
    ctx.express.use(ctx.config.routes.admin, await ctx.config.admin.bundler.serve(ctx))
    } else {
    ctx.express.use(ctx.config.routes.admin, await ctx.config.admin.bundler.dev(ctx))
    }

  • default discord avatar
    mryellow10 months ago

    This may be when build:payload (Which should be simply the webpack bundler) has failed to be ran. Due to failure on some systems.

    With the TypeScript I had Error: unknown field cwd same as other reports:

    https://help.railway.app/questions/i-want-to-deploy-a-nextjs-project-with-p-dc946ee6
    https://help.railway.app/questions/error-unknown-field-cwd-when-building-edc1598f
    swc-project/swc#7538 (comment)

    Now with a Javascript version of the files I get:

    > cross-env PAYLOAD_CONFIG_PATH=src/payload.config.js payload build
    
    /home/user/path/node_modules/@swc/wasm/wasm.js:489
        const ret = new Error(getStringFromWasm0(arg0, arg1));
                    ^
    
    Error: invalid type: unit value, expected a map
    

    #6611

  • discord user avatar
    jmikrut
    9 months ago

    Hey @mryellow - yes, you'll need to copy over your build folder as well if you want to run Payload in production. Without a built copy of the admin UI, the admin UI will not work in production.

    Give that a shot!

    1 reply
    default discord avatar
    mryellow9 months ago

    There is nothing in that directory which requires such opinionated build tooling.

    (Tooling which was bugged and blocked the entire project from functioning.)

    It's simply a directory of static assets. It could be committed.

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.