Pages fails to build with webpack and React

I am using a react with webpack, the build works fine locally, but the cloudflare page is unable to build it. It keeps throwing the following error
npm ERR! npm ci can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with npm install before continuing.
npm ERR! npm ci can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with npm install before continuing.
How do i solve thsi?
2 Replies
Miracle Matthew
The error generally means your package.json and package-lock.json have gotten out of sync. Cloudflare Pages (or any CI/CD environment) will insist they match before running npm ci. You can resolve it using these commands in the order the appear; 1. rm -rf node_modules - to remove any existing node_modules folder (locally) 2. npm install - installs your packages again to generate a fresh matching package-lock.json Also ensure's your package.json and package-lock.json are in sync 3. git add package.json package-lock.json git commit -m "Fix package-lock.json" - Use it to commit the changes to both files in your repository. 4. npm run build - you can then fetch your build and run it on Cloudflare page
Art_Paul
Art_PaulOP4w ago
Ya fixed it. Thanks btw.

Did you find this page helpful?