When using GitHub Actions CI to build the project, the workflow fails during the build step with the following error: Error: Error: missing secret key. A secret key is needed to secure Payload.
The error seems to indicate that the Payload CMS requires a secret key to be provided during the build process. However, even after configuring the environment variables in the GitHub repository settings, the error persists.
name: ci
on: [pull_request]
jobs:
build:
name: ci github
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.x
cache: 'npm'
- name: Install dependencies
run: npm install
- name: Linting
run: npm run lint
- name: Testing
run: npm run test:ci
- name: Build
run: npm run build
Do you have a repository we can see the code? Do you have any plugins running? What is the exact error message log? More infomration could help us troubleshoot
Of course, I removed the CI build to continue development (it's a test project for the payloadCMS behavior) but all the code is there.
What does your env file / env variables naming look like in Github and you have the full build error?
How about locally - can you build it locally?
PAYLOAD_SECRET=
DATABASE_URI=
WEBHOOK_URL=
NODE_ENV=
PAYLOAD_CONFIG_PATH=
BLOB_READ_WRITE_TOKEN=
SMTP_HOST=
SMTP_USER=
SMTP_PASS=
SMTP_PORT=
Collecting page data ...
Error: Error: missing secret key. A secret key is needed to secure Payload.
at tu.init (/home/runner/work/new-portfolio/new-portfolio/.next/server/chunks/7383.js:107:15330)
at async tp (/home/runner/work/new-portfolio/new-portfolio/.next/server/chunks/7383.js:107:18346)
at async Object.u [as generateStaticParams] (/home/runner/work/new-portfolio/new-portfolio/.next/server/app/(portfolio)/projects/[slug]/page.js:1:8465)
at async builtRouteParams (/home/runner/work/new-portfolio/new-portfolio/node_modules/next/dist/build/utils.js:987:36)
Yes, locally it does not show any build errors.
However, even after configuring the environment variables in the GitHub repository settings,
I do not see evidence of this in your rolled back commit
Your workflow doesn't look to be loading any environment variables
You can likely just set this on your build step.
- name: Build
run: npm run build
env:
PAYLOAD_SECRET: 'anything'Thanks for your help
@967118574445547650, I managed to define it through GitHub secrets with the following CI
name: ci
on: [pull_request]
jobs:
build:
name: ci github
environment: build
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.x
cache: 'npm'
- name: Install dependencies
run: npm install
- name: Linting
run: npm run lint
- name: Testing
run: npm run test: ci
- name: Build
run: npm run build
env:
PAYLOAD_SECRET: ${{ secrets.PAYLOAD_SECRET }}
DATABASE_URI: ${{ secrets.DATABASE_URI }}
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}
BLOB_READ_WRITE_TOKEN: ${{ secrets.BLOB_READ_WRITE_TOKEN }}
Star
Discord
online
Get dedicated engineering support directly from the Payload team.