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
How do i solve thsi?
2 Replies
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
Ya fixed it. Thanks btw.