I am wondering if it is possible to run a command that would check that the package is a valid npm package, add it to package.json as a dependency, but not install it.
I am doing this because I have a certain package installed globally and need to require it for an open source project. Hence, I wish it to be included.
Install the dependencies in the local node_modules folder. In global mode (ie, with -g or --global appended to the command), it installs the current package context (ie, the current working directory) as a global package. By default, npm install will install all modules listed as dependencies in package. json .
npm ci will install packages based on package-lock. json file and if the file does not exist or does not match the packages specified in the package.
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.
The Npm command not found error can appear when you install or upgrade npm. On Windows, the cause of this error could be that a PATH or system variable is not correctly set. The error can also occur if you do not have npm or Node. js installed, have an outdated version, or have permission issues.
The correct way to only update package.json, without any other side-effects is:
npm install --save --package-lock-only --no-package-lock <package>
Use --package-lock-only
to prevent writing to node_modules.
The --package-lock-only argument will only update the package-lock.json, instead of checking node_modules and downloading dependencies.
Then, use --no-package-lock
to prevent the creation of the lock file:
The --no-package-lock argument will prevent npm from creating a package-lock.json file. When running with package-lock's disabled npm will not automatically prune your node modules when installing.
See npm install docs for more.
I don't think yo can do that with npm. I've looked into the docs and I didn't find anything about.
You can use this as a workarround:
npm i <package> --save && npm uninstall <package>
Hope it helps.
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