Support Forums

I am trying to host my react on netlify but there is a install npm error

Hi guys! I need some help! I’m trying to host on my reacy website on netlify but npm install error happens. Could you help me with solving this problem?

Hiya, sorry you are having trouble with your build.

This Support Guide contains a ton of useful debugging tips that can likely help you solve your problem :slight_smile:

We also recommend trying to search the forums with the build error you encountered - it’s likely your question was already asked by someone else!

If you are still having problems, please provide as much information as you can on what you have already tried, what your build settings are, your package.json , etc. Thanks!

I tried to solve this problem several days :frowning: I also asking and finding this kind of issue in other communities but still struggling with it. I didn’t change any Netlify settings. I will attatch my package.json screen shot file! @perry

Hi @JiwanJeon

I believe the error you are facing is the same as that in Build Problems but works on local machine.

Hi there @coelmay ! I also saw that question that you linked to me, but I couldn’t understand and follow the solution. If you don’t mind, can you explain it in detail?

As in the screenshot of your package.json (text is preferable to images if possible) and original error message, you are using webpack 5.40.0 however as per the line

npm ERR! peer webpack@"^4.0.0" from optimize-css-assets-webpack-plugin@6.0.1

this dependency is requiring webpack 4.

As mentioned in the thread previously linked to, you could downgrade the version of webpack you are using to satisfy the dependency (note: this may also break other things in your project, so you would ideally test locally first) or use the NPM_FLAGS environment variable to add --legacy-peer-deps to ignore the conflict (again, as the warning suggests, this may break things.)

Does this clear up any confusion?

1 Like

Dear coelmay, @coelmay

First of all, thank you for explaining in detail.
To be honest, I tried it over 10 times :frowning: Even though I tried making a new repository, the same errors come out… It is weird when I tried to upload my files to Netlify directly(Get started with Netlify CLI | Netlify Docs), it works. However, when I tried to upload my files through GitHub, the netlify deploy log show the same error. I guess when I run “npm install” to my mac terminal, it shows same error message but I can handle it because I can fix it with this command with --force, or --legacy-peer-deps this command, but I couldn’t solve it at Netlify because I couldn’t type those command to Netlify.
Every time I upload my files and push them to my GitHub, netlify shows the same error. I stuck this problem for over 3 weeks :frowning:

Hi @JiwanJeon

You can pass those flags through to the build script in Netlify as I explained previously

More specifically, navigate to https://app.netlify.com/sites/<your-site-name>/settings/deploys#environment and add the NPM_FLAGS variable like this

1 Like

Dear coelmay,

Oh my god! Now, I understand you mentioned this comment " use the NPM_FLAGS environment variable to add --legacy-peer-deps to ignore the conflict (again, as the warning suggests, this may break things.)"
I didn’t know that I have to write those commands to Netlify Environment variables. For now, it totally works!!! Thank you so much! I really appreciate it! You save my life.

1 Like