node.js ENOENT,没有这样的文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20753550/
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
ENOENT, no such file or directory
提问by Kinnard Hockenhull
I'm getting this error from my node app:
我从我的节点应用程序中收到此错误:
ENOENT, no such file or directory '~/Desktop/MyApp/newversion/partials/navigation.jade'
I know the file is there because when I try to open the file using the exact copied and pasted path, it works. I also know the application is using the right directory because, well, it outputs it in the error.
我知道文件在那里,因为当我尝试使用精确复制和粘贴的路径打开文件时,它可以工作。我也知道应用程序正在使用正确的目录,因为它在错误中输出它。
采纳答案by hobbs
Tilde expansion is a shell thing. Write the proper pathname (probably /home/yourusername/Desktop/etcetcetc) or useprocess.env.HOME + '/Desktop/blahblahblah'
波浪号扩展是壳的东西。写下正确的路径名(可能是/home/yourusername /Desktop/etcetcetc)或使用process.env.HOME + '/Desktop/blahblahblah'
回答by grepit
回答by Thisuri
- First try
npm install,if the issue is not yet fixed try the following one after the other. npm cache clean,thennpm install -g npm,thennpm install,Finallyng serve --oto run the project. Hope this will help....
- 第一次尝试
npm install,如果问题尚未解决,请一个接一个地尝试。 npm cache clean,然后npm install -g npm, 那么npm install, 最后ng serve --o运行项目。希望这会有所帮助......
回答by Still_learning
I was also plagued by this error, and after trying all the other answers, magically found the following solution:
我也被这个错误困扰,在尝试了所有其他答案后,神奇地找到了以下解决方案:
Delete package-lock.json and the node_modules folder, then run npm installagain.
删除 package-lock.json 和 node_modules 文件夹,然后npm install再次运行。
If that doesn't work, try running these in order:
如果这不起作用,请尝试按顺序运行这些:
npm install
npm cache clean
npm install -g npm
npm install
(taken from @Thisuri's answer and @Mathias Falci's comment respectively)
(分别取自@Thisuri 的回答和@Mathias Falci 的评论)
and then re-deleting the above files and re-running npm install.
然后重新删除上述文件并重新运行npm install.
Worked for me!
对我来说有效!
回答by BraveNewMath
__dirname
Gives you the current node application's rooth directory.
为您提供当前节点应用程序的 rooth 目录。
In your case, you'd use
在你的情况下,你会使用
__dirname + '/Desktop/MyApp/newversion/partials/navigation.jade';
See this answer:
看到这个答案:
回答by Sanjay
I had that issue : use path module
我有这个问题:使用路径模块
const path = require('path');
and also do not forget to create the uploads directory first period.
并且不要忘记创建上传目录第一期。
回答by sfscs
For me, it was having my code folder in Dropbox on windows 10. During the build process Dropbox would flip out over having more than 500,000 files. I moved my folder out and now it builds fine!
对我来说,它在 Windows 10 上的 Dropbox 中有我的代码文件夹。在构建过程中,Dropbox 会因为拥有超过 500,000 个文件而崩溃。我把我的文件夹移了出来,现在它构建得很好!
回答by maxshuty
Another possibility is that you are missing an .npmrcfile if you are pulling any packages that are not publicly available.
另一种可能性是,.npmrc如果您正在提取任何未公开提供的软件包,则您会丢失一个文件。
You will need to add an .npmrcfile at the root directory and add the private/internal registry inside of the .npmrcfile like this:
您需要.npmrc在根目录中添加一个文件,并在文件中添加私有/内部注册表,.npmrc如下所示:
registry=http://private.package.source/secret/npm-packages/
回答by Earl Lapura
For those running Laravel Mix with npm run watch, just terminate the script and run the command again.
对于那些使用 运行 Laravel Mix 的人npm run watch,只需终止脚本并再次运行命令。


