I have added a new page today and pushed everything to my github, then the build has failed.
To be honest, I don’t know what is going on, I have only added a new component which is a new page, that’s all. I haven’t added any NPM libraries from the last commit with succesfull build.
The error is a peer dependency conflict relating to versions of react, which provides guidance on how you can attempt to resolve it:
11:06:39 AM: npm ERR! Fix the upstream dependency conflict, or retry
11:06:39 AM: npm ERR! this command with --force, or --legacy-peer-deps
11:06:39 AM: npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
It suggests you can run npm install --force or npm install --legacy-peer-deps.
To do this on Netlify you can use the NPM_FLAGS environment variable.
NPM_FLAGS: used to indicate the flags to pass to the npm install command.
Setting it to either --force or --legacy-peer-deps depending on your preference.
This fixed the issue I had today But what is the reason it becomes an issue all of a sudden? The source code and settings were never changed for months
@hrishikesh I mean why did it suddenly break specifically in Netlify with 16.15.1? I have been using the —legacy-peer-deps flag to make my package-lock file since npm 8.0.0, and only now is Netlify giving me a build error.
Additionally, I can still build and serve this package locally. There has to be something more happening here.
Something is causing the need to set the legacy-peer-deps flag in Netlify’s environmental variables specifically with Node 16.15.1.
This isn’t a npm 7+ thing. This is specifically an issue with the way Netlify is building packages with npm v8.11.0, which requires an env var that was not required with v8.5.5.
We’ve done nothing special to change this behaviour. There’s no reason for Netlify to trigger a change that would specifically affect a minor x.x.1 update in Node.js and break so many builds.
I’ve always used the NODE_VERSION as node in my Site Settings. So I have been using version 16.5.1+ much before it went into the “latest LTS” stage a few days ago and I’m having this issue since then.
To be clear, we’re not doing anything special with building packages or installing Node Modules. We’re simply calling npm install:
Now why that breaks, especially due to a change of version with Node.js? I think that’s a question for the variable that’s changing here.
These packages build fine locally with the proper install flags, so whether it makes sense or not, this is an issue affecting Netlify. Might be worth looking into a bit further.
Does Netlify not use package-lock when installing?
I’ve encountered the same issue starting with 16.15.1.
Setting NPM_FLAGS to --legacy-peer-deps has resolved it for now.
The package-lock.json was built with --legacy-peer-deps.