简体   繁体   English

节点 Nodemon 错误:找不到模块 'C:\Program Files\Git\node_modules\nodemon\bin\nodemon.js'

[英]Node Nodemon Error: Cannot find module 'C:\Program Files\Git\node_modules\nodemon\bin\nodemon.js'

  • I am a beginner at NodeJS stuff.我是 NodeJS 的初学者。
  • Environment is Windows 7 64 Bit.环境是 Windows 7 64 位。
  • Node is installed and working.节点已安装并正在运行。
  • NPM is also working fine. NPM 也运行良好。
  • Nodemon is installed.安装了 Nodemon。 (In App and also Globally) (在应用程序和全球范围内)

Now when I run the command:现在当我运行命令时:

"nodemon server.js" or just "nodemon" “nodemon server.js”或只是“nodemon”

it gives the following error:它给出了以下错误:

module.js:549
    throw err;
    ^

Error: Cannot find module 'C:\Program Files\Git\node_modules\nodemon\bin\nodemon.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3
  • I don't understand what this means?我不明白这是什么意思? And why is it looking inside the Git folder?为什么它会在 Git 文件夹中查找?
  • Does it have to do anything with Environment Variable?它与环境变量有什么关系吗? But Node and NPM are both working fine.但是 Node 和 NPM 都运行良好。
  • Any ideas/suggestion/solution?有什么想法/建议/解决方案吗?

Below is my "server.js" file in case you need for reference.以下是我的“server.js”文件,以供您参考。

var express = require("express");
var bodyParser = require("body-parser");
var morgan = require("morgan");
var path = require("path");

var app = express();
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());

app.use(function (req, es, next) {
    res.setHeader("Access-Control-Allow-Origin", "*");
    res.setHeader("Access-Control-Allow-Methods", "GET, POST");
    res.setHeader("Access-Control-Allow-Headers", "X-Requested-With, content-type, Authorization");
    next();
});

app.use(morgan("dev"));
app.use(express.static(__dirname + "/app"));
app.get("*", function (req, res) {
    res.sendFile(path.join(__dirname + "/index.html"));
});

app.listen(8080);
console.log(">>>>> App is Running <<<<<");

remove node_modules in your project and than install reagain nodemon module, run below commands;删除项目中的 node_modules 并重新安装 nodemon 模块,运行以下命令;

 rm -rf node_modules npm install -g npm@latest npm i nodemon

In my case it was same issue I solved it by mentioned method hope it will help you so in package.json in script tag就我而言,这是同样的问题,我通过提到的方法解决了它希望它会在脚本标签中的 package.json 中对您有所帮助

  "start":"nodemon index.js"

   

and in terminal with this command run并在终端中使用此命令运行

  nodemon start

您必须验证服务器名称 (servers.js) 在文件夹中的名称是否相同,( package.json ) 验证main启动您不应该为 nodemon 创建文件夹。

make sure you are running the server.js is in the root directory and run this command in root directory of your project确保您正在运行 server.js 在根目录中并在项目的根目录中运行此命令

nodemon ./server.js

Also you can rename server.js to index.js and just run您也可以将 server.js 重命名为 index.js 并运行

nodemon

More on nodemon: https://www.npmjs.com/package/nodemon有关 nodemon 的更多信息: https ://www.npmjs.com/package/nodemon

使用命令: npm run server而不是 nodemon server.js,您将得到缺少哪个模块的确切错误。

I think this is a typical path problem.我认为这是一个典型的路径问题。 You need to fix your environment variable PATH for npm to execute correctly.您需要修复环境变量 PATH 以使 npm 正确执行。

the path you need to add looks like: C:\Program Files\nodejs\node_modules\npm\bin您需要添加的路径如下所示: C:\Program Files\nodejs\node_modules\npm\bin

Find the PATH env var and add the path you expect your npm packages to install from!找到 PATH 环境变量并添加您希望安装 npm 包的路径!

Or you can navigate to that directory and execute: npm config set prefix或者您可以导航到该目录并执行: npm config set prefix

Nodemon is looking for the main config in the package.json, Which may be missing. Nodemon 正在寻找 package.json 中的主要配置,这可能会丢失。 try to add main property in package.json with the key of your entry file.尝试使用入口文件的键在 package.json 中添加 main 属性。 for example:-例如:-

"main":"src/main.ts"

“开始”:“nodemon src/app.js”

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

相关问题 节点 Nodemon 错误:找不到模块 &#39;C:\\Program Files\\nodejs\\node_modules\\nodemon\\bin\\&#39; - Node Nodemon Error: Cannot find module 'C:\Program Files\nodejs\node_modules\nodemon\bin\' 节点找不到模块 'D:\Education\nodemon\bin\nodemon.js' - Node Cannot find module 'D:\Education\nodemon\bin\nodemon.js' nodemon 错误:错误:找不到模块“vue” - nodemon error: Error: Cannot find module 'vue' 安装 Drivelist 时找不到模块 &#39;C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin&#39; - Cannot find module 'C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin' While installing Drivelist 用于带有Nodemon的Visual Studio的节点 - Node for Visual Studio with Nodemon nodemon 找不到模块&#39;/path/to/project/home/index.js&#39; - nodemon Cannot find module '/path/to/project/home/index.js' 在 node js 服务器的终端中无法识别 nodemon 命令 - nodemon command is not recognized in terminal for node js server Windows 上 node.js 的 IISNode 和/或 nodemon - IISNode and/or nodemon for node.js on Windows internal/modules/cjs/loader.js:960 错误:找不到模块'C:\Users\Sanjai\AppData\Roaming\npm\node_modules\protractor\bin\protractor' - internal/modules/cjs/loader.js:960 Error: Cannot find module 'C:\Users\Sanjai\AppData\Roaming\npm\node_modules\protractor\bin\protractor' node 和 nodemon 有什么区别? - What is difference between node and nodemon?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM