- site name: pyth-on-line.netlify.app
- build logs: Netlify App
Most of modern JavaScript package managers suppress peerdependencies warnings, but npm does not.
The behavior of npm
is weird:
- The first time it will warn user about peerDependencies
- If a
node_modules
exists, it will throw peerDependencies as errors
So everytime I deploy with cache, it fails for peerDependencies. But if I deploy without cache, it successes.
I don’t like locking the package manager in package.json
and don’t want to upload a lock file either. So I can’t set the package manager to replace npm
manually.
I think there are several ways to resolve this common use case:
- support setting package manager through env / in
netlify.toml
/ in the build settings UI
- support setting install command that automatically runes during
Initializing
step
- support to opt-out some commands in
Initializing
step
- support to opt-out caching of build
- support custom cleanup commands (so that I may remove
node_modules
)
Any approach from the above can resolve this.
@muspi-merol It may not be applicable for your situation, (and doesn’t align with your wider configuration requests), but have you considered trying the legacy-peer-deps
flag?
https://docs.npmjs.com/cli/v9/using-npm/config#legacy-peer-deps
It can be applied with the NPM_FLAGS
environment variable, for which there is more detail here:
https://answers.netlify.com/t/deploy-failed-today-build-was-terminated-build-script-returned-non-zero-exit-code-1/64450/2
With #5, if you did want to delete your node_modules
you could just do so within your build command, as the node_modules
won’t be in your Publish directory they could be safely deleted after build but prior to deployment.
1 Like
Thank you a lot! Setting NPM_FLAGS
did resolve my problem. Apologize for having not read through documents for the npm cli.
About #5, I found that some of my netlify functions relies on the node_modules
so I can’t remove it in the build command. But excluding it in the build cache may be useful.
You can also specify NPM_FLAGS as --dry-run
to prevent installing anything from NPM.