简体   繁体   English

部署在 Heroku 上的节点应用程序立即崩溃

[英]Node app deployed on Heroku immediately crashes

***fixed, thank you all who helped. ***已修复,感谢所有帮助的人。

Hello thank you for attempting to help me.您好,感谢您尝试帮助我。 I have looked through google and here for a fix but to no avail.我已经通过谷歌和这里查看了修复但无济于事。 This is the first question I have asked so if I'm not clear or specific enough I apologize and will try to clear it up as best as I can.这是我提出的第一个问题,所以如果我不够清楚或不够具体,我深表歉意,并会尽我所能解决问题。

I have recently deployed an app on heroku using a free dyno(their node.js buildpack).我最近使用免费的测功机(他们的 node.js buildpack)在 heroku 上部署了一个应用程序。

This app runs perfectly fine on my localhost.这个应用程序在我的本地主机上运行得很好。 When I start the deploy process and check the logs I am met with this error:当我开始部署过程并检查日志时,我遇到了这个错误:

    2021-05-16T21:03:07.870774+00:00 heroku[web.1]: State changed from crashed to starting
2021-05-16T21:03:14.868295+00:00 heroku[web.1]: Starting process with command `npm start`
2021-05-16T21:03:18.871696+00:00 app[web.1]: 
2021-05-16T21:03:18.871706+00:00 app[web.1]: > server@1.0.0 start /app
2021-05-16T21:03:18.871707+00:00 app[web.1]: > nodemon index.js
2021-05-16T21:03:18.871707+00:00 app[web.1]: 
2021-05-16T21:03:19.162417+00:00 app[web.1]: [33m[nodemon] 2.0.7[39m
2021-05-16T21:03:19.167339+00:00 app[web.1]: [33m[nodemon] to restart at any time, enter `rs`[39m
2021-05-16T21:03:19.167341+00:00 app[web.1]: [33m[nodemon] watching path(s): *.*[39m
2021-05-16T21:03:19.167341+00:00 app[web.1]: [33m[nodemon] watching extensions: js,mjs,json[39m
2021-05-16T21:03:19.167342+00:00 app[web.1]: [32m[nodemon] starting `node index.js index.js`[39m
2021-05-16T21:03:19.271336+00:00 app[web.1]: internal/modules/cjs/loader.js:888
2021-05-16T21:03:19.271342+00:00 app[web.1]:   throw err;
2021-05-16T21:03:19.271342+00:00 app[web.1]:   ^
2021-05-16T21:03:19.271343+00:00 app[web.1]: 
2021-05-16T21:03:19.271343+00:00 app[web.1]: Error: Cannot find module '/app/index.js'
2021-05-16T21:03:19.271379+00:00 app[web.1]:     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:885:15)
2021-05-16T21:03:19.271580+00:00 app[web.1]:     at Function.Module._load (internal/modules/cjs/loader.js:730:27)
2021-05-16T21:03:19.271582+00:00 app[web.1]:     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
2021-05-16T21:03:19.271583+00:00 app[web.1]:     at internal/main/run_main_module.js:17:47 {
2021-05-16T21:03:19.271587+00:00 app[web.1]:   code: 'MODULE_NOT_FOUND',
2021-05-16T21:03:19.271587+00:00 app[web.1]:   requireStack: []
2021-05-16T21:03:19.271588+00:00 app[web.1]: }
2021-05-16T21:03:19.279342+00:00 app[web.1]: [31m[nodemon] app crashed - waiting for file changes before starting...[39m
2021-05-16T21:04:15.043653+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2021-05-16T21:04:15.098622+00:00 heroku[web.1]: Stopping process with SIGKILL
2021-05-16T21:04:15.255205+00:00 heroku[web.1]: Process exited with status 137
2021-05-16T21:04:15.331085+00:00 heroku[web.1]: State changed from starting to crashed

I have tried changing my start script to not include nodemon, I have tried moving my index.js to app/index.js as it says in that log, I've tried changing the start script with any combination of "node index.js" "nodemon index.js"我已尝试将启动脚本更改为不包含 nodemon,我已尝试将我的 index.js 移动到 app/index.js,正如该日志中所述,我已尝试使用“node index.js”的任意组合更改启动脚本" "nodemon index.js"

I have no clue why it won't work properly.我不知道为什么它不能正常工作。 At the end of that log it also times out due to not binding with the $PORT even though I have it set as process.env.PORT.在该日志的末尾,即使我将其设置为 process.env.PORT,它也由于未与 $PORT 绑定而超时。

Any suggestions are welcomed and if I need to provide any more code, please let me know.欢迎任何建议,如果我需要提供更多代码,请告诉我。

Here is the file structure for the app: File structure这是应用程序的文件结构:文件结构

Here is the structure of my index.js: index.js这是我的 index.js 的结构: index.js

This may not be your main error but need to set your environment variabels seperately for heroku, heroku does not read from your local.env file.这可能不是您的主要错误,但需要为 heroku 单独设置您的环境变量,heroku 不会从您的 local.env 文件中读取。

You can set these by going to your app and then under settings->config vars, here you can just copy and paste the key/values from your.env file one by one.您可以通过转到您的应用程序然后在 settings->config vars 下进行设置,在这里您可以一一复制并粘贴 your.env 文件中的键/值。

I think this is the reason why it's failing我认为这就是它失败的原因

[32m[nodemon] starting `node index.js index.js`[39m
2021-05-16T21:03:19.271336+00:00 app[web.1]: internal/modules/cjs/loader.js:888
2021-05-16T21:03:19.271342+00:00 app[web.1]:   throw err;

I Think your node run script is wrong its trying to run node index.js index.js我认为你的节点运行脚本是错误的,它试图运行node index.js index.js

Check your Package.json file检查您的 Package.json 文件

Potential Problem 2潜在问题 2

If not the above then 2nd issue I see is the path of index.js如果不是上述,那么我看到的第二个问题是 index.js 的路径

2021-05-16T21:03:19.271343+00:00 app[web.1]: Error: Cannot find module '/app/index.js'
2021-05-16T21:03:19.271379+00:00 app[web.1]:     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:885:15)
2021-05-16T21:03:19.271580+00:00 app[web.1]:     at Function.Module._load (internal/modules/cjs/loader.js:730:27)

do you have the index.js at the same level as package.json OR is it located inside of a folder?您是否拥有与 package.json 相同级别的 index.js 或者它是否位于文件夹内? Because as you see the Error Log it says cannot load module /app/index.js [assuming /app/ is your root folder]因为当您看到错误日志时,它说无法加载模块/app/index.js [假设/app/是您的根文件夹]

This can also happen if the file starts with Capital I and in node script you have small i or vice a versa如果文件以大写I开头并且在节点脚本中您有小i或反之亦然,也会发生这种情况

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

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