How to add npm module without changing old dependencies in package-lock.json? - npm

I use npm ci to install npm modules and it install same package versions as in package-lock.json
And now I need to add npm module for starting write unit tests, I use this command: npm i jest
I expect that it should add only jest dependencies, but npm update all out-of-date dependencies of 3-5 level dependencies in package-lock.json
I would like to do something like this npm ci --save-dev jest
How to install npm package without changing old dependencies in package-lock.json?
UPD For example, please clone this repo, after that use npm ci and npm i empty-module, if you look at git diff you'll see a lot of changes of package-lock.json file

Related

What does "npm rebuild" actually do?

I've been struggling with a module that does not build after running npm rebuild (namely, #getinsomnia/node-libcurl), even though it does on npm install without --ignore-scripts.
I workaround that by running npx node-pre-gyp install in the module directory, but I'd like to understand why doesn't this behave as I expect it to do - build the module.
npm docs for npm rebuild say:
This command runs the npm build command on the matched folders.
What does npm build do though? Documentation for it only exists for npm v6 and not any newer releases, I can't run npm build on my npm v8 either ("unknown command"), and even that documentation doesn't say anything to me:
This is the plumbing command called by npm link and npm install.
It should generally be called during installation, but if you need to run it directly, run:
npm build

What is the difference between the following npm install statements?

npm install #uiw/react-monacoeditor --save
VS
npm i #uiw/react-monacoeditor
What is the difference between following npm install statements when to use --save flag?
Currently they will not differ at all. Since NPM 5 packages are automatically saved into package.json dependencies when installed.
npm I is the short version of npm install so that part of the command does not differ at all either.
You can read more about the install command here: https://docs.npmjs.com/cli/v8/commands/npm-install
And there is does say “ npm install saves any specified packages into dependencies by default.”

How to manage a non-node module as dependency for Node Project thorugh NPM?

I was using bower in my project for dependency management. But now I wanted to move to node and npm. But the problem is few of my dependencies are not node modules like Smooth-Div-Scroll1 and swiftype-search-jquery2
How to manage all those dependencies in my node project. When I tried doing
"swiftype-search-jquery": "git#github.com:swiftype/swiftype-search-jquery.git",
"smooth-div-scroll": "git#github.com:tkahn/Smooth-Div-Scroll.git",
it is not able to download dependency and throw error
npm ERR! code ENOPACKAGEJSON npm ERR! package.json Non-registry package missing package.json: swiftype-search-jquery#git+ssh://git#github.com/swiftype/swiftype-search-jquery.git. npm ERR! package.json npm can't find a package.json file in your current directory.
These dependencies don't have package.json in their folder.
I don't think it's possible.
Here is a guide to migrate from bower to npm, it's pretty easy.
https://codecraft.tv/courses/angularjs-migration/step-2-typescript-and-webpack/converting-bower-to-npm/
Yup, It is not possible with NPM but at the same time, it is possible with Yarn without making any change. Instead of "npm install" we have to use "yarn install" .
Add dependencies with git url which is not present with NPM .

How do I apply changes in package-lock and package json?

I manually changed my dependencies in package-lock.json and package.json files. How do I now apply those changes to my node-modules without updating/touching other dependencies?
Run command
npm i
or
npm install --save
npm i command will install all your dependencies into your local machine which are available in the file.
PS: It is not recommended approach to directly update package.json file, always install package using command npm i packageName --save or npm i packageName --save --dev. This will install as well as Update your package.json file too.

Abandoned question: Why does 'npm install' remove my packages?

The command is npm install --save file-saver and it returns this:
npm WARN The package enzyme is included as both a dev and production dependency.
npm WARN The package gulp-util is included as both a dev and production dependency.
npm WARN The package react-addons-test-utils is included as both a dev and production dependency.
+file-saver#1.3.3
added 1 package and removed 15 packages in 6.536s
I know two of the packages removed are react-google-recaptcha and react-async-script. Also, I'm not using npm's public registry.