Preview not working with Nextjs deployed with CF Pages

For Workers & Pages, what is the name of the domain?

Not deployed yet

What is the issue or error you’re encountering

I was able to set up my Nextjs project in Cloudflare but the preview is failing because is not loading the npm token in the build

What steps have you taken to resolve the issue?

I set up the npm token as a secret in the preview and production tabs
When I create a new PR the preview build is running and it fails with 401 because the token is undefined. I think the problem is that you need a wrangler to make Next works with CF Pages and this is not allowing secrets in the dashboard
If I merge the PR to main branch the deployment works well, the problem is the preview. I would like to have the preview branch URL on every PR.

What are the steps to reproduce the issue?

Set up a Nextjs project with a npm private package and set a secret for it.
Run the install in local so you check it works.
Deploy your project in CF Pages, set the secret for the preview tab in the dashboard.
When you run the preview deployment the packages installation will fail because the env var is undefined.

20:18:03.285 ▲ Detected bun.lock generated by [email protected]
20:18:03.286 ▲ Warning: Bun is used as a package manager at build time only, not at runtime with Functions
20:18:03.293 ▲ Installing dependencies…
20:18:03.305 ▲ bun install v1.2.14 (6a363a38)
20:18:13.276 ▲ error: GET https://npm.fontawesome.com/@fortawesome/fontawesome-svg-core/-/fontawesome-svg-core-6.7.2.tgz - 401
20:18:13.277
20:18:13.277 ▲ error: GET https://npm.fontawesome.com/@fortawesome/react-fontawesome/-/react-fontawesome-0.2.2.tgz - 401
20:18:13.277
20:18:13.277 ▲ error: GET https://npm.fontawesome.com/@fortawesome/free-solid-svg-icons/-/free-solid-svg-icons-6.7.2.tgz - 401
20:18:13.278
20:18:13.278 ▲ error: GET https://npm.fontawesome.com/@fortawesome/pro-regular-svg-icons/-/pro-regular-svg-icons-6.7.2.tgz - 401
20:18:13.303 ▲ Error: Command bun install exited with 1
20:18:13.341
20:18:13.342 :high_voltage: The Vercel build (bunx vercel build) command failed. For more details see the Vercel logs above.
20:18:13.342 :high_voltage: If you need help solving the issue, refer to the Vercel or Next.js documentation or their repositories.
20:18:13.342
20:18:13.356 Failed: Error while executing user command. Exited with error code: 1
20:18:13.368 Failed: build command exited with code: 1
20:18:14.402 Failed: error occurred while running build command

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.