可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
npm install
/ npm install -g
command is not working in Windows 7
Node.js is installed properly, node.js version is v0.10.28
Couldn't read dependencies
ENOENT, open '"filepath"\package.json'
This is most likely not a problem with npm itself.
npm can't find a package.json file in your current directory.
回答1:
You don't say what module you want to install - hence npm looks for a file package.json
which describes your dependencies, and obviously this file is missing.
So either you have to explicitly tell npm which module to install, e.g.
npm install express
or
npm install -g express-generator
or you have to add a package.json
file and register your modules here. The easiest way to get such a file is to let npm create one by running
npm init
and then add what you need. Please note that this does only work for locally installed modules, not for global ones.
A simple example might look like this:
{
"name": "myapp",
"version": "0.0.1",
"dependencies": {
"express": "4.0.0"
}
}
or something like that. For more info on the package.json
file see its official documentation and this interactive guide.
回答2:
node
comes with npm
installed so you should have a version of npm
, however npm
gets updated more frequently than node
does, so you'll want to make sure it's the latest version.
sudo npm install npm -g
Test: Run npm -v
. The version should be higher than 2.1.8.
npm install
THAT'S IT!
https://www.youtube.com/watch?v=wREima9e6vk
回答3:
I'm not sure what you're trying to do here:
npm install
alone in your home directory shouldn't do much -- it's not the root of a node app, so there's nothing to install, since there's no package.json.
There are two possible solutions:
1) cd
to a node app and run npm install
there. OR
2) if you're trying to install something as a command to use in the shell (You don't have a node application), npm install -g packagename
. -g
flag tells it to install in global namespace.
回答4:
>> For Visual Studio Users using Package Manager Console <<
If you are using the Package Manager Console in Visual Studio and you want to execute:
npm install
and get:
ENOENT: no such file or directory, open
'C:\Users...\YourProject\package.json'
Verify that you are executing the command in the correct directory.
VS by default uses the solution folder when opening the Package Manager Console.
Execute dir
then you can see in which folder you currently are. Most probably in the solution folder, that's why you get this error.
Now you have to cd
to your project folder.
cd YourWebProject
Now npm install
should work now, if not, then you have another issue.
回答5:
Use below command to create a package.json file.
npm init
npm init --yes or -y flag
[This method will generate a default package.json using information extracted from the current directory.]
Working with package.json
回答6:
In my case there was mistake in my package.json:
npm ERR! package.json must be actual JSON, not just JavaScript.
回答7:
Check this link for steps on how to install express.js for your application locally.
But, if for some reason you are installing express globally, make sure the directory you are in is the directory where Node is installed.
On my Windows 10, package.json is located at
C:\Program Files\nodejs\node_modules\npm
Open command prompt as administrator and change your directory to the location where your package.json is located.
Then issue the install command.
回答8:
I was facing the same issue as below.
npm ERR! errno -4058 npm ERR! syscall open npm ERR! enoent ENOENT: no
such file or directory, open
'D:\SVenu\FullStackDevelopment\Angular\Angular2_Splitter_CodeSkeleton\CodeSke
leton\run\package.json' npm ERR! enoent This is related to npm not
being able to find a file. npm ERR! enoent
The problem I made was, I was running the command npm build run
instead of running npm run build
.
Just sharing to help someone who does small mistakes like me.