简体   繁体   English

如何修复“nodemon app crashed”错误消息?

[英]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:我尝试了以下解决方案:

  1. https://stackoverflow.com/a/54450694/14537132 https://stackoverflow.com/a/54450694/14537132
  2. https://stackoverflow.com/a/63298885/14537132 https://stackoverflow.com/a/63298885/14537132
  3. Deleting nodemone.json and re-creating the file删除 nodemone.json 并重新创建文件
  4. Deleting the node modules file & re-installing it删除节点模块文件并重新安装

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.

相关问题 nodemon 应用程序在生产中崩溃(没有错误),在 localhost 中工作 - nodemon app crashed (without error) in production, works in localhost mondoDB 的 Nodemon 错误:“应用程序崩溃 - 启动前等待文件更改” - Nodemon error with mondoDB: “ app crashed - waiting for file changes before starting” nodemon 应用程序崩溃 - 并返回 ERR MODULE NOT FOUND 错误 - nodemon app crashed - and returning error that ERR MODULE NOT FOUND 当我运行 nodemon 服务器时,我收到错误消息“错误的身份验证失败。[nodemon] 应用程序崩溃 - 在开始之前等待文件更改......” - When I run nodemon server I get the error "bad auth Authentication failed. [nodemon] app crashed - waiting for file changes before starting..." 如何修复Nodemon“异步删除{}”语法错误? - How to fix Nodemon "async remove {}" syntax error? 如何修复 Windows 上的 Nodemon 内部监视错误? - How to Fix Nodemon internal watch error on windows? 如何修复wp超级缓存错误消息? - How do I fix wp super cache error message? nodemon 应用程序崩溃 - 在从服务器获得响应后开始错误之前等待文件更改 - nodemon app crashed - waiting for file changes before starting error after geting response from server 节点 js 错误:[nodemon] 应用程序崩溃 - 启动前等待文件更改 - Node js error: [nodemon] app crashed - waiting for file changes before starting Nodemon应用程序崩溃-当我从rest发送发帖请求时 - Nodemon app crashed - when i send a post request from restEasy chrome extension
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM