node.js npm install 导致“ENOENT:没有这样的文件或目录”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38143558/
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 resulting in 'ENOENT: no such file or directory'
提问by Alex Godbehere
I've installed Node.js for Windows and I'm trying to install a package via npm. The command prompt is in the directory of the project (C:\Users\username\Desktop\NodeTest), which contains a single helloworld.js file. Upon typing 'npm install express', I receive the following error:
我已经为 Windows 安装了 Node.js,我正在尝试通过 npm 安装一个包。命令提示符位于项目目录 (C:\Users\username\Desktop\NodeTest) 中,其中包含一个 helloworld.js 文件。输入“npm install express”后,我收到以下错误:
ENOENT: no such file or direcotry, open 'C:\Users\username\package.json
ENOENT: no such file or direcotry, open 'C:\Users\username\package.json
I'm attempting this from a clean install and cmd is running as admin.
我正在从全新安装中尝试此操作,并且 cmd 以管理员身份运行。
Any ideas?
有任何想法吗?
采纳答案by DAXaholic
As already pointed out by Subburaj this is because you are missing a package.json.
Just run npm initto initialize that file for you; afterwards it should work.
正如 Subburaj 已经指出的那样,这是因为您缺少package.json.
只需运行npm init即可为您初始化该文件;之后它应该工作。
回答by Vicky
I was facing the same issue. I firstly delete my node_modulesand delete the cache by following command:
我面临着同样的问题。我首先node_modules通过以下命令删除我的并删除缓存:
rm -rf node_modules && npm cache clean --force
then I delete the package-lock.jsonfile from my project and then hit npm installin command prompt and it works.
然后我package-lock.json从我的项目中删除该文件,然后npm install在命令提示符下点击它就可以了。
回答by Aravindh S
Basically I was Offline while I tried to install with npm, so go online and try
npm installagain
基本上我在尝试使用 npm 安装时处于离线状态,所以请上网再试
npm install一次
回答by Mushtaque Ahmed
Check the project folder which you opened in microsoft visual code. Generally you are not in the right path so npm is not able to search the package.json ... My project was in Document/hostel/hostel .. I opened Document/hostel ... So npm tried to find the package.json in Documents folder .. When i entered one level inside to Document/hostel/hostel .. it was fixed.
检查您在 microsoft visual code 中打开的项目文件夹。通常,您不在正确的路径中,因此 npm 无法搜索 package.json ... 我的项目位于 Document/hostel/hostel .. 我打开了 Document/hostel ... 所以 npm 试图找到 package.json在 Documents 文件夹中 .. 当我进入 Document/hostel/hostel 里面的一层时..它被修复了。

