Reputation: 100010
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?
Upvotes: 9
Views: 36489
Reputation: 2929
You can use below command line:
npm install packegName --loglevel=error
It will only show errors. For example, a problem in the download or the package cant be found.
Upvotes: 1
Reputation: 29172
Try this:
rm -r -f ./node_modules/PACKAGE_NAME && \
mkdir -p ./node_modules/ && \
npm pack PACKAGE_NAME | xargs tar -C ./node_modules -xzf && \
mv ./node_modules/package ./node_modules/PACKAGE_NAME && \
rm PACKAGE_NAME *.tgz
Upvotes: 1
Reputation: 114
package.json file not only contains your project information, but also contains dependencies, which makes your project self contained and deploy easily. however, you can still install a package without package.json file globally by running npm install bar -g
but that won't be part of you project dependency, it will be in you local machine only.
so, the question depends on you purpose actually, but as I mentioned, its possible to install npm packages globally without package.json file. Just you have to install that again when you move your project to another PC or server if that is your purpose.
Upvotes: -2
Reputation: 31
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
.
Upvotes: 3