Dependencies ignored and deleted from package-lock.json after npm install - javascript

I'm trying to run an JS Chrome extension from a cloned repository. The problem occurs after I run npm install where some of the dependencies in the package-lock.json file gets deleted and essentially ignored. This causes the project to miss many of the modules necessary for it to run.
I've tried using npm ci but it still has the same problem. I've also tried using yarn and yarn check but to no avail. What is the problem here? Why doesn't npm install all the dependencies in package-lock.json file without having to delete some of them?

Related

yarn.lock file is not updating after I update the version of a dependency in package.json and run yarn install or just yarn

In the repository of a project, I already have package.json and yarn.lock files. I'm updating the version of a particular package from version 2.0.14 to version 2.0.16.
When I do yarn install or just yarn, I can see the changes related to the updated package but the yarn.lock file is not updating.
Is there is any command to generate the updated yarn.lock file?
Try using yarn install --force as this will re-download all packages (in their locked versions unless too old) and refresh the lock file if necessary. yarn install should already do this, but in case it doesn't, you can force it to.

Why npm installation decrease dependencies versions

I have a problem while installing package using npm it is decreasing dependencies versions that breaks my application and unit tests, for example my package.lock file fater instalation looks like:
Please tell me how can I install package without decreasing dependencies versions ?
You could try to use npm ci:
In short, the main differences between using npm install and npm ci are:
The project must have an existing package-lock.json or npm-shrinkwrap.json.
If dependencies in the package lock do not match those in package.json, npm ci will exit with an error, instead of updating the package lock.
npm ci can only install entire projects at a time: individual dependencies cannot be added with this command.
If a node_modules is already present, it will be automatically removed before npm ci begins its install.
It will never write to package.json or any of the package-locks: installs are essentially frozen.
https://docs.npmjs.com/cli/v6/commands/npm-ci

Unable to do `npm start`

I did an npx create-react-app then I did an npm start to see if it worked, and when I did it, it gave me this error I don't really know why it is giving me this error, but I tried everything that it said, yet it keeps giving the error.
You should remove the node_modules folder inside your home folder, the one at C:\Users\Simone\node_modules. Also, double-check that you don't have a package.json or package-lock.json files in your home folder.
It looks like the error is related to a version conflict for that dependency. You could uninstall your version of Webpack with npm uninstall webpack, add the below dependency to your package.json file, then run npm i to get up-to-date.
"webpack": "4.44.2"

runtime.js file always romoved when I install other packages

Whenever I install some packages, runtime.js in regenerator-runtime always removed..
So I always have prepared that files in other folder and pasted when I install some..
It's very vexing thing to me.
It's all same in my all projects where I have this package
who know why this happen??
I don't know why this happens.
just uninstall all node packages and reinstall them then, this problem go away..
Remove yarn.lock (or package.lock)
yarn (npm install)

In production, should i clean and reinstall node_modules everytime I deploy?

We have more than 10 instances of prod servers and each time we update our dependencies, so cleaning and re-installing sounds more controlled, but also a bit slower.
Problem is the devops team complain about the time taken to do a clean (after removing existing node_modules) npm install everytime package.json changes.
We have noticed sometimes our build breaks on prod if we do run update or install on existing node_modules.
Are there any best practices for production deployment?
How can i optimize the process of updating the node_modules safely here?
In newer npm version, there is a feature for locking the version of your dependencies.
There is a file called package-lock.json along with package.json. That lock file
will lock the dependency version while you install it on dev environment. So, when you install it on production from package.json using npm install, it will fetch locked version from package-lock.json file and will install specific version same as dev environment.
That means you don't need to clean node_module folder every time on production. You can just install new added dependency from package.json file and its version will be taken from package-lock.json file.
There is another package manager called "yarn" is there which provide same feature, but if you want to stick to npm, then its now possible with new npm version.
After a couple of months breaking my head on this. I came across this package on NPM:
npm-check-updates.
npm-check-updates allows you to upgrade your package.json dependencies to the latest versions.
All you have to do is run
npm install npm-check-updates --save
ncu -u
npm install
This works very nicely for me.

Categories

Resources