Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm install: Is there a way to ignore a particular dependency in package.json

Tags:

I am currently trying to create a docker container for a node.js project that contains a local dependency. This seems to cause an issue with docker so as a workaround I am trying to just copy the local dependency folders and just ignore their dependency entries in the package.json file. Is there a way to specify dependencies I would like to ignore and have npm install run and skip those enties?

like image 570
user1790300 Avatar asked Nov 19 '17 05:11

user1790300


People also ask

Does npm install install optional dependencies?

The installed package will be put into optionalDependencies . When you want to avoid installing optional dependencies, you can execute npm ci --no-optional (e.g. on CI tools like GitLab CI). Use npm ci to install all dependencies, including optional dependencies (e.g. on your development environment).

How npm install specific dependencies?

For npm install specific version, use npm install [package-name]@[version-number]. Use npm view [package-name] version to know the specific latest version of a package available on the npm registry. Use npm list [package-name] to know the specific latest version of an installed package.

What is npm install -- ignore scripts?

The --ignore-scripts argument will cause npm to not execute any scripts defined in the package. json. See scripts . The --legacy-bundling argument will cause npm to install the package such that versions of npm prior to 1.4, such as the one included with node 0.8, can install the package.

How do I remove a dependency from a package?

To remove a dev dependency, you need to attach the -D or --save-dev flag to the npm uninstall, and then specify the name of the package. You must run the command in the directory (folder) where the dependency is located. I will be using Nodemon to demonstrate how to remove a dev dependency.


1 Answers

That can be done using devDependencies

The npm modules which you require only to develop, e.g.: unit tests, Coffeescript to Javascript transpilation, minification etc,make the required module a devDependency.

To skip Installation of devDepenencies pass --production flag to npm install,with the --production flag(or NODE_ENV environment variable set to production) npm will not install modules listed in devDependencies."

npm install --production 

To make any module to be part of devDependencies pass --dev while installing.

npm install packagename --save-dev 
like image 127
RootHacker Avatar answered Sep 24 '22 02:09

RootHacker