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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 16:33:25  来源:igfitidea点击:

ENOENT, no such file or directory

node.jsexpress

提问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 use
process.env.HOME + '/Desktop/blahblahblah'

波浪号扩展是壳的东西。写下正确的路径名(可能是/home/yourusername /Desktop/etcetcetc)或使用
process.env.HOME + '/Desktop/blahblahblah'

回答by grepit

I believe the previous answer is the correct answer to this problem but I was getting this error when I tried installing npm package (see below) :

我相信上一个答案是这个问题的正确答案,但是当我尝试安装 npm 包时出现了这个错误(见下文):

enter image description here

在此处输入图片说明

The fix for me was : npm init --yes

对我来说修复是: npm init --yes

enter image description here

在此处输入图片说明

回答by Thisuri

  1. First try npm install,if the issue is not yet fixed try the following one after the other.
  2. npm cache clean,then
  3. npm install -g npm,then npm install,Finally
  4. ng serve --oto run the project. Hope this will help....
  1. 第一次尝试npm install,如果问题尚未解决,请一个接一个地尝试。
  2. npm cache clean,然后
  3. npm install -g npm, 那么 npm install, 最后
  4. 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:

看到这个答案:

App base path from a module in NodeJS

来自 NodeJS 模块的应用程序基本路径

回答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,只需终止脚本并再次运行命令。