node.js npm install 给出错误“找不到 package.json 文件”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24468041/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
npm install gives error "can't find a package.json file"
提问by Subhajit Panja
npm install/ npm install -gcommand is not working in Windows 7
npm install/npm install -g命令在 Windows 7 中不起作用
Node.js is installed properly, node.js version is v0.10.28
node.js安装正确,node.js版本为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.
无法读取依赖项
ENOENT,打开 '"filepath"\package.json'
这很可能不是 npm 本身的问题。
npm 在您的当前目录中找不到 package.json 文件。


回答by Golo Roden
You don't say what module you want to install - hence npm looks for a file package.jsonwhich describes your dependencies, and obviously this file is missing.
您没有说明要安装哪个模块 - 因此 npm 会查找一个package.json描述您的依赖项的文件,显然该文件丢失了。
So either you have to explicitly tell npm which module to install, e.g.
所以要么你必须明确告诉 npm 要安装哪个模块,例如
npm install express
or
或者
npm install -g express-generator
or you have to add a package.jsonfile and register your modules here. The easiest way to get such a file is to let npm create one by running
或者您必须在package.json此处添加文件并注册您的模块。获取此类文件的最简单方法是让 npm 通过运行创建一个
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.jsonfile see its official documentationand this interactive guide.
回答by Cosimo de' Medici
nodecomes with npminstalled so you should have a version of npm, however npmgets updated more frequently than nodedoes, so you'll want to make sure it's the latest version.
node随附npm安装,因此您应该拥有 的版本npm,但是npm更新的频率比node它高,因此您需要确保它是最新版本。
sudo npm install npm -g
Test: Run npm -v. The version should be higher than 2.1.8.
测试:运行npm -v。版本应高于2.1.8。
npm install
THAT'S IT!
就是这样!
回答by Nerve
I'm not sure what you're trying to do here:
我不确定您要在这里做什么:
npm installalone 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.
npm install单独在您的主目录中不应该做太多事情——它不是节点应用程序的根目录,因此没有什么可安装的,因为没有 package.json。
There are two possible solutions:
有两种可能的解决方案:
1) cdto a node app and run npm installthere. OR
1)cd到节点应用程序并在npm install那里运行。或者
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. -gflag tells it to install in global namespace.
2) 如果您尝试将某些东西安装为要在 shell 中使用的命令(您没有节点应用程序),则npm install -g packagename. -g标志告诉它安装在全局命名空间中。
回答by Legends
>> For Visual Studio Users using Package Manager Console <<
>> 对于使用包管理器控制台的 Visual Studio 用户 <<
If you are using the Package Manager Console in Visual Studio and you want to execute:
如果您在 Visual Studio 中使用包管理器控制台并且想要执行:
npm installand get:
npm install并得到:
ENOENT: no such file or directory, open 'C:\Users...\YourProject\package.json'
ENOENT:没有这样的文件或目录,打开“C:\Users...\YourProject\package.json”
Verify that you are executing the command in the correct directory.
验证您是否在正确的目录中执行命令。
VS by default uses the solution folderwhen opening the Package Manager Console.
VS在打开包管理器控制台时默认使用解决方案文件夹。
Execute dirthen 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 cdto your project folder.
执行dir然后你可以看到你当前在哪个文件夹中。很可能在解决方案文件夹中,这就是您收到此错误的原因。现在你必须到cd你的项目文件夹。
cd YourWebProject
cd YourWebProject
Now npm installshould work now, if not, then you have another issue.
现在npm install应该可以工作了,如果不行,那么你还有另一个问题。
回答by krish007
Use below command to create a package.json file.
使用以下命令创建 package.json 文件。
npm init
npm init --yes or -y flag
[This method will generate a default package.json using information extracted from the current directory.]
[此方法将使用从当前目录中提取的信息生成默认的 package.json。]
回答by Vikas
Check this linkfor steps on how to install express.js for your application locally.
检查此链接以获取有关如何在本地为您的应用程序安装 express.js 的步骤。
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
但是,如果由于某种原因您要全局安装 express,请确保您所在的目录是安装 Node 的目录。在我的 Windows 10 上,package.json 位于
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.
以管理员身份打开命令提示符并将目录更改为 package.json 所在的位置。
Then issue the install command.
然后发出安装命令。
回答by Sibeesh Venu
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
错误!错误号 -4058 npm 错误!系统调用打开 npm ERR!enoent ENOENT:没有那个文件或目录,打开'D:\SVenu\FullStackDevelopment\Angular\Angular2_Splitter_CodeSkeleton\CodeSkeleton\run\package.json' npm ERR!enoent 这与 npm 无法找到文件有关。错误!恩恩特
The problem I made was, I was running the command npm build runinstead of running npm run build.
我遇到的问题是,我正在运行命令npm build run而不是运行npm run build.
Just sharing to help someone who does small mistakes like me.
只是分享以帮助像我这样犯小错误的人。
回答by Alexander Polishchuk
In my case there was mistake in my package.json:
就我而言,我的 package.json 中有错误:
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR! package.json must be actual JSON, not just JavaScript.

