![](/img/trans.png)
[英]nodemon app crashed - waiting for file changes before starting… nodejs
[英]NODEMON -- app crashed - waiting for file changes before starting
當我運行npm run server
時,在視頻中的 13:10,我收到錯誤:
[nodemon] app crashed - waiting for file changes before starting...
為什么會這樣? 端口 5000 是否已在使用?
這是終端:
#########:MERN_SHOPPING_LIST #######$ npm run server
mern_shopping_list@1.0.0 server /Users/MyName/Documents/Web Dev/MERN_SHOPPING_LIST
nodemon server.js
[nodemon] 1.18.3
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node server.js`
/Users/MyName/Documents/Web Dev/MERN_SHOPPING_LIST/server.js:1
(function (exports, require, module, __filename, __dirname) { const express = required('express');
^
ReferenceError: required is not defined
at Object.<anonymous> (/Users/MyName/Documents/Web Dev/MERN_SHOPPING_LIST/server.js:1:79)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
[nodemon] app crashed - waiting for file changes before starting...
簡單的答案是:
進入Mongodb集群,編輯IP白名單並刷新
然后再次連接問題解決。
快樂編碼
首先,這是什么(function (exports, require, module, __filename, __dirname) { ... })
? 它是模塊包裝函數。 當拋出異常時,模塊已經有了它的包裝函數。
讓我們來看看錯誤。
1 > const express = required('express');
^
這就是你的錯字所在。
現在讓我們進入[nodemon]
。
您收到來自“ [nodemon]
”的錯誤消息的原因是您正在為服務器使用名為nodemon的開發工具。
你用了一個詞required
它是require
。
代碼應該是require('express');
在server.js file
第 1 行。
每當您遇到錯誤時, nodemon
嘗試為您重新啟動程序。 如果您效應的變化,或讓你不會需要運行該命令的必要的修正node server.js
一次。
這是一個非常常見的錯誤,當您使用 nodemon 啟動服務器時,您可能會遇到此錯誤。 那么,這到底是怎么回事? 解決辦法是什么?
錯誤原因和解決方案:
第一的:
也許您的 PC 在后台運行多個進程。 所以你需要停止所有正在運行的節點進程。
快速技巧,通過在終端上運行這個來殺死他們:
pkill -f node
或者殺死一個特定的端口而不是全部
sudo lsof -i :8000 //replace 3000 with your port number
sudo kill -9 51009 // replace 31363 with your PID
然后重啟nodemon。
第二:
Server.js 和 package.json 不在同一個文件夾中。
//check package.json
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon Server.js"
}
第三:
您在任何文件中編寫了錯誤的代碼。 因此,請確保您沒有遺漏任何 JS 語法。 如果你寫錯了代碼,這里我說的是語法錯誤(不是邏輯),那么你的 nodemon 將不會啟動。
大佬們注意了
問題可能出在文件夾中。
我按文件夾更改了任何檔案,但我無法使用 npm run dev 成功。
查看檔案和其他文件,如果有人不在原始文件夾中,可能是錯誤的
問題不是 npm run dev 或 nodemon
查看導致 nodemon 應用程序崩潰的文件。 對 Me express 的該文件示例進行更改不起作用:
我做了: npm 安裝
npx 節點監視器
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.