[英]How do I fix a "nodemon app crashed" error message?
I have just worked through chapter 2 of the book Full Stack React Projects, Second Edition .我刚刚完成了Full Stack React Projects, Second Edition这本书的第 2 章。
When I type into the Terminal yarn development
to check my code, I get this error message:当我输入终端yarn development
来检查我的代码时,我收到以下错误消息:
yarn run v1.22.15
warning package.json: License should be a valid SPDX license expression
$ nodemon
[nodemon] 2.0.2
[nodemon] to restart at any time, enter `rs`
[nodemon] watching dir(s): server/**/*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `webpack --mode=development --config webpack.config.server.js && node ./dist/server.generated.js`
Hash: 7630758f261bc6024be1
Version: webpack 4.42.1
Time: 475ms
Built at: 10/06/2021 2:48:53 PM
Asset Size Chunks Chunk Names
server.generated.js 19.4 KiB main [emitted] main
Entrypoint main = server.generated.js
[0] multi ./server/server.js 28 bytes {main} [built]
[./node_modules/webpack/buildin/harmony-module.js] (webpack)/buildin/harmony-module.js 573 bytes {main} [built]
[./node_modules/webpack/buildin/module.js] (webpack)/buildin/module.js 497 bytes {main} [built]
[./server/devBundle.js] 1.6 KiB {main} [built]
[./server/server.js] 2.19 KiB {main} [built]
[./template.js] 1.15 KiB {main} [built]
[./webpack.config.client.js] 1.8 KiB {main} [built]
[express] external "express" 42 bytes {main} [built]
[mongodb] external "mongodb" 42 bytes {main} [built]
[path] external "path" 42 bytes {main} [built]
[webpack] external "webpack" 42 bytes {main} [built]
[webpack-dev-middleware] external "webpack-dev-middleware" 42 bytes {main} [built]
[webpack-hot-middleware] external "webpack-hot-middleware" 42 bytes {main} [built]
webpack:///./server/server.js?:23
app.use('/dist', express__WEBPACK_IMPORTED_MODULE_0___default.a.static(path__WEBPACK_IMPORTED_MODULE_2___default.a.join(CURRENT_WORKING_DIR, 'dist')));
^
ReferenceError: Cannot access 'app' before initialization
at Module.eval (webpack:///./server/server.js?:23:1)
at eval (webpack:///./server/server.js?:65:30)
at Module../server/server.js (/Users/brittanysoozinsoozin/Library/Mobile Documents/com~apple~CloudDocs/Desktop/Desktop/TMDP/Molo9/Dev/Full Stack React/Ch2/MyCode/dist/server.generated.js:132:1)
at __webpack_require__ (/Users/brittanysoozinsoozin/Library/Mobile Documents/com~apple~CloudDocs/Desktop/Desktop/TMDP/Molo9/Dev/Full Stack React/Ch2/MyCode/dist/server.generated.js:21:30)
at eval (webpack:///multi_./server/server.js?:1:18)
at Object.0 (/Users/brittanysoozinsoozin/Library/Mobile Documents/com~apple~CloudDocs/Desktop/Desktop/TMDP/Molo9/Dev/Full Stack React/Ch2/MyCode/dist/server.generated.js:166:1)
at __webpack_require__ (/Users/brittanysoozinsoozin/Library/Mobile Documents/com~apple~CloudDocs/Desktop/Desktop/TMDP/Molo9/Dev/Full Stack React/Ch2/MyCode/dist/server.generated.js:21:30)
at /Users/brittanysoozinsoozin/Library/Mobile Documents/com~apple~CloudDocs/Desktop/Desktop/TMDP/Molo9/Dev/Full Stack React/Ch2/MyCode/dist/server.generated.js:85:18
at Object.<anonymous> (/Users/brittanysoozinsoozin/Library/Mobile Documents/com~apple~CloudDocs/Desktop/Desktop/TMDP/Molo9/Dev/Full Stack React/Ch2/MyCode/dist/server.generated.js:88:10)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
[nodemon] app crashed - waiting for file changes before starting...
I have tried the following solutions:我尝试了以下解决方案:
How do I fix this?我该如何解决?
Deleting the node modules file won't solve your issue since the problem according to the error log isn't with any of the packages used in your app.删除节点模块文件不会解决您的问题,因为根据错误日志的问题与您的应用程序中使用的任何包无关。 Your app issue originates most likely from your server.js file as seen in your error log如错误日志中所示,您的应用程序问题很可能源于您的 server.js 文件
ReferenceError: Cannot access 'app' before initialization
at Module.eval (webpack:///./server/server.js?:23:1)
at eval (webpack:///./server/server.js?:65:30)
at Module../server/server.js (/Users/brittanysoozinsoozin/Library/Mobile Documents/com~apple~CloudDocs/Desktop/Desktop/TMDP/Molo9/Dev/Full Stack React/Ch2/MyCode/dist/server.generated.js:132:1)
at __webpack_require__ (/Users/brittanysoozinsoozin/Library/Mobile Documents/com~apple~CloudDocs/Desktop/Desktop/TMDP/Molo9/Dev/Full Stack React/Ch2/MyCode/dist/server.generated.js:21:30)
at eval (webpack:///multi_./server/server.js?:1:18)
what I can see is that the crash happens when nodejs tries to access the static files of your app which you declared in your server.js file on line 23 .我能看到的是,当 nodejs 尝试访问您在第 23 行的server.js文件中声明的应用程序的static 文件时发生崩溃。
You did not initialize the app variable before you used it on line 23. You would need to do something like this:在第 23 行使用它之前,您没有初始化app变量。您需要执行如下操作:
const app = require('./app'); // this will import your app.js file that is in your root folder assuming you are using that type of setup.
Also, check if the " dist " file path is correct.另外,检查“ dist ”文件路径是否正确。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.