简体   繁体   English

找不到节点模块。找不到模块

[英]node module not found .MODULE NOT FOUND

node app.js
node:internal/modules/cjs/loader:998
  throw err;
  ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\app.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
    at Module._load (node:internal/modules/cjs/loader:841:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []

i was trying to get the node code to work basically node app.js我试图让节点代码基本上工作 node app.js

Look into your project directory where you initialized node app.js .查看初始化node app.js的项目目录。 The issue is that you're not in the project directory where this file exists.问题是您不在该文件所在的项目目录中。 Go into the project directory and launch your node app.js . Go 进入项目目录并启动你的node app.js

90% sure, hopefully this will fix it. 90% 肯定,希望这会解决它。

This error usually occurs when you're not in the right folder.当您不在正确的文件夹中时,通常会发生此错误。 Here you're in C:\Program Files\nodejs\node_modules\npm and you're trying to run your file App.js which is stored elsewhere on your computer.在这里,您位于C:\Program Files\nodejs\node_modules\npm并且您正在尝试运行存储在计算机其他位置的文件App.js

I'd recommend going through these simple steps to fix the problem: (let's say you want Node to run your file App.js .我建议通过这些简单的步骤来解决问题:(假设您希望Node运行您的文件App.js

  1. Check whether or not your file exist in the current working directory (the error says it isn't there) with one of the commands:使用以下命令之一检查您的文件是否存在于当前工作目录中(错误说它不存在):
    ls (bash, shell, powershell) or dir (cmd). ls (bash、shell、powershell)或dir (cmd)。
  • If your file ( App.js ) is listed on the output of the above command, then check the spelling and make sure the case exactly matches what you provided to node .如果您的文件 ( App.js ) 在上述命令的 output 中列出,请检查拼写并确保大小写与您提供给node的内容完全匹配。 That is you command must be node App or node App.js and not node app.js or node aPP.js ...那就是你的命令必须是node Appnode App.js而不是node app.jsnode aPP.js ...

  • If your file isn't listed (what is the more probable outcome) then go to step 2 .如果您的文件未列出(更可能的结果是什么),则 go 到step 2


  1. Get the full path of the folder containing your file ( App.js ) from your file explorer.从文件资源管理器中获取包含文件 ( App.js ) 的文件夹的完整路径。
  • On windows, just open the folder containing your file and copy the content of the address bar.在 windows 上,只需打开包含您的文件的文件夹并复制地址栏的内容即可。
  • On Linux, refer to this question . Linux上,参考这个问题
  • On Mac, refer to this other question在 Mac 上,请参阅其他问题

  1. In your terminal navigate to the above folder with the command在您的终端中,使用以下命令导航到上述文件夹
    cd copied_path . cd copied_path

  1. Check again the content of the path to make sure your command line is opened in the right folder.再次检查路径的内容以确保您的命令行在正确的文件夹中打开。

  1. Run node App.js运行node App.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM