Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install NPM dependency into folder that does not contain package.json

I have a directory that looks like so

/foo

yep it's an empty folder, I want to run

cd foo && npm install bar

however npm is complaining that there is no package.json file in the foo directory.

Is there a bonafide reliable way to install a depedency into a directory if there is no package.json file there (yet)?

Turns out, it was just a warning, not a error, I misread, it says:

npm WARN enoent ENOENT: no such file or directory, open '/home/olegzandr/.suman/package.json'

I guess my question then becomes, is there a way to tell NPM to ignore a missing package.json file?

like image 724
Alexander Mills Avatar asked Dec 04 '16 05:12

Alexander Mills


People also ask

How do I force npm to install dependencies?

NPM installs devDependencies within the package. json file. The 'npm install' command should add all the dependencies and devDependencies automatically during installation. If you need to add specific devDependencies to your project, you can use this command- 'npm install --save-dev'.

Does npm need package json?

All npm packages contain a file, usually in the project root, called package. json - this file holds various metadata relevant to the project. This file is used to give information to npm that allows it to identify the project as well as handle the project's dependencies.

Does npm install install everything in Package json?

By default, npm install will install all modules listed as dependencies in package.json . With the --production flag (or when the NODE_ENV environment variable is set to production ), npm will not install modules listed in devDependencies .


2 Answers

Deleting package-lock.json solved for me.

like image 156
Thalinda Bandara Avatar answered Oct 20 '22 20:10

Thalinda Bandara


One of the primary reasons for a package.json is to document the dependencies that a given application has. With that said, you can either run npm init in your directory to create a package.json or install the package globally using npm install -g bar.

like image 3
Dillon Avatar answered Oct 20 '22 20:10

Dillon