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?
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'.
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.
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 .
Deleting package-lock.json solved for me.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With