Environment variables not working with PayloadCMS
timburton97
FREEOP

2 months ago

On the build log, I am getting this error message:

Error: Error: missing secret key. A secret key is needed to secure Payload.

at bE.init (.next/server/chunks/9506.js:488:6790)

at async bH (.next/server/chunks/9506.js:488:10686)

at async Object.o [as generateStaticParams] (.next/server/app/(frontend)/posts/page/[pageNumber]/page.js:2:14251) {

payloadInitError: true

}

This is the section of the dockerfile the build fails on:

RUN \
  if [ -f yarn.lock ]; then yarn run build; \
  elif [ -f package-lock.json ]; then npm run build; \
  elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
  else echo "Lockfile not found." && exit 1; \
  fi

Here is the build script that it is failing on:

"build": "cross-env NODE_OPTIONS=--no-deprecation next build"

I have set the PAYLOAD_SECRET variable in the variables to the correct key. I have spelled the variable names correctly. Is there anything I need to change to my dockerfile or my build script?

Thank you,

Tim

Solved$10 Bounty

3 Replies

Railway
BOT

2 months ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


timburton97
FREEOP

2 months ago

I should also note that my variables are showing correctly in the deployment details, it is just unable to get the PAYLOAD_SECRET variable during the build process


brody
EMPLOYEE

2 months ago

This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.

Status changed to Open brody 2 months ago


dev
MODERATOR

2 months ago

To use that variable during build time you'll need to specify them via arg in your Dockerfile script

More Info: https://docs.railway.com/guides/dockerfiles#using-variables-at-build-time


Status changed to Solved brody 2 months ago


Loading...