Managing node modules in npm5 - node.js

I'm still using node v6 and npm v3 and planning to move to node v8 and npm v5
I use npm in client(Angular2) and server side(Express)
These are the steps i follow to manage node modules in
npm v3
to save in package.json and update npm-shrinkwrap.json
npm install packagename#version --save
to save in package.json dependency and not to update npm-shrinkwrap.json
npm install packagename#version --save-dev
npm install will install dependency and dependencies but will not update npm-shrinkwrap.json file
npm run build builds front end code using webpack
npm prune --production removes all devDependencies after the build process and will not update npm-shrinkwrap.json file
What i'm facing in
npm 5.4.2
npm install installs modules and updatespackage-lock.json with dependency and devDependencies if any change in version
npm run build builds front end code using webpack
npm prune --production removes all devDependencies from node_modules and package-lock.json
How we can enforce keeping dependency alone in package-lock.json ?
Any other recommendations on build process ?
Should we keep devDependencies in node_modules if its not used in production?
------ Update on 10/25/2017 -------
To remove devDependencies without updating package-lock.json
try npm prune --production --no-package-lock

Related

npm install but in package-lock, npmjs changes to yarnpkg

What I did:
Git pull from main
run nvm use to use node v14.17.6 (npm v6.14.15) then npm install
delete package-lock.json then run npm install again
After steps 2 and 3, for some dependencies package-lock.json, npmjs changed to yarnpkg.
Questions:
Why did this happen since this project does not use yarn
How can I fix this
try this -
npm cache clear - -force
npx rimraf ./**/node_modules
del package-lock.json
now run npm install again

react : NPM install fails

I tried installing a package in my react app using npm, and for some reason It fails:
it shows the following error:
npm ERR! Object for dependency "#babel/generator" is empty.
npm ERR! Something went wrong. Regenerate the package-lock.json with "npm install".
npm ERR! If using a shrinkwrap, regenerate with "npm shrinkwrap".
I tried npm install to regenerate the package-lock.json but it's the same as before.
TLDR
There is some dependency error with npm, so how about clear project
Answer
First of all, How about clear node_modules and package-lock.json
rm -rf ./node_modules package-lock.json
and retry install with
npm install or npm i
and what I want to say is clear package-lock.json and node_modules. If you'd like to get more information about deleting here is the link
What version of the babel (and it's sub-modules) do you use? Show rows from your package.json file (related to babel).
Your issue possibly could be resolved by updating all babel-related modules

What's the difference between depenencies and devDependencies with NPM 5

The below question refers to a project I'm not publishing to npm.
In NPM 3, if I had a package in devDependencies and ran shrinkwrap (without --development) then npm-shrinkwrap.json would not include the packages in devDependencies.
But with NPM 5, packages in dependencies and devDependencies are added to package-lock.json, with those from devDependencies having "dev": true.
So, if I'm just using npm install x to add packages and npm install to install everything on, say, a build server, is a package listed in dependencies treated any differently from a package listed in devDependencies?
It will make sense on production. When you'll need to install all packages, except dev.
npm i --production
From npmjs.org:
With the --production flag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in devDependencies.

What NPM command should users run if the package.json file has been updated?

If I update the package.json file in an NPM workflow app, what command do existing users run to update their local node_modules dependencies?
To start using it, they run:
$ npm install
So what do they run if there is a change to the package.json file? Or do they just delete the folder and re-run the npm install command?
To re-validate the package.json and install adjusted versions or new packages:
$ npm install
The one thing this won't do is remove packages that aren't in package.json. To do that, run:
$ npm prune
If you've only changed package versions and not added new packages:
$ npm update
If you you've updated a specific package version:
$ npm update {packagename}
You should either do
npm install && npm prune
or
npm upgrade && npm prune
npm install will be faster than npm upgrade because it only updates packages in node_modules if package.json demands a newer version. npm uprade, on the other hand, will download updates to dependencies if they are available, which may include bug fixes. For ≥npm-5, you should use npm install because npm upgrade will have the side-effect of modifying any package-lock.json file which should not be modified unless if you are the package’s maintainer.
npm prune is necessary because the updates to package.json may have removed dependencies. If you do not run npm prune, packages installed by a prior version of package.json will remain in the node_modules directory that would not be there if you freshly downloaded/cloned the project and ran npm install. Due to how some packages conditionally call require() or even scan the node_modules directory, leaving packages which were removed from package.json can result in unexpected behavior.

NPM install delete node modules NPM install

I am adding a node module to a project of mine and I am not able to build the project till I do an npm install delete the node modules folder and do an npm install again. Just deleting the node modules and doing an npm install does not fix it.

Resources