Whenever I run npm install <package>
it installs the package alright, but then it automatically runs the prepare
script.
It's worth mentioning that I've already checked that there is no postinstall
script in the package.json.
To stop a running npm process, press CTRL + C or close the shell window.
The easiest way to fix the issue is to pass an additional parameter –legacy-peer-deps to npm install. The --legacy-peer-deps tells the npm to ignore the peer dependencies and continue the installation of the package. Try the below command to install the dependencies for your project.
prepare (since [email protected] ) Runs any time before the package is packed, i.e. during npm publish and npm pack. Runs BEFORE the package is packed. Runs BEFORE the package is published. Runs on local npm install without any arguments.
Use the npm start to start a package. As of the [email protected], you can make use of custom arguments when executing scripts. This command is used to stop a package. This command will run the stop script that is provided by the package.
From https://docs.npmjs.com/misc/scripts:
prepare: Run both BEFORE the package is packed and published, and on local npm install without any arguments (See below). This is run AFTER prepublish, but BEFORE prepublishOnly.
Since NPM v5, prepare
script is executed when you run npm install
The other answers are fine, but for some additional context, this is to support a workflow where you can use devDependencies to build assets or other generated content for your project.
For example, say you want to use node-sass (CSS preprocessor). You add "node-sass" as a devDependency, then you run the sass command in your "prepare" script, which generates your CSS.
So, when you run npm install
, the following happens:
And when you run npm publish
, something similar happens:
So now when someone comes along and installs your package, they don't need node-sass or any of your devDependencies. They only need to runtime deps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With