Heroku Deploy错误:找不到模块'/app/index.js'

时间:2021-05-07 19:41:49

I' m trying to deploy mt app on Heroku but I always get the same error:

我正在尝试在Heroku上部署mt app,但我总是得到同样的错误:

2016-08-18T10:16:10.988982+00:00 heroku[web.1]: Starting process with command `node index.js`
2016-08-18T10:16:13.180369+00:00 app[web.1]: module.js:341
2016-08-18T10:16:13.180389+00:00 app[web.1]:     throw err;
2016-08-18T10:16:13.180390+00:00 app[web.1]:     ^
2016-08-18T10:16:13.180391+00:00 app[web.1]: 
2016-08-18T10:16:13.180392+00:00 app[web.1]: Error: Cannot find module '/app/index.js'
2016-08-18T10:16:13.180393+00:00 app[web.1]:     at Function.Module._resolveFilename (module.js:339:15)
2016-08-18T10:16:13.180394+00:00 app[web.1]:     at Function.Module._load (module.js:290:25)
2016-08-18T10:16:13.180394+00:00 app[web.1]:     at Function.Module.runMain (module.js:447:10)
2016-08-18T10:16:13.180399+00:00 app[web.1]:     at node.js:405:3
2016-08-18T10:16:13.271966+00:00 heroku[web.1]: Process exited with status 1
2016-08-18T10:16:13.273383+00:00 heroku[web.1]: State changed from starting to crashed

As I read in similar requests I have already added a Procfile containing the following code: web: node index.js, but I still have same issue.

当我在类似的请求中读到时,我已经添加了包含以下代码的Procfile:web:node index.js,但我仍然遇到同样的问题。

Anybody have any idea where the problem is? Any guidance would be greatly appreciated. Thank you in advance!

任何人都知道问题出在哪里?任何指导将不胜感激。先谢谢你!

2 个解决方案

#1


4  

Add relative path for index.js file as bellow

为index.js文件添加相对路径,如下所示

web: node ./index.js

#2


2  

If you do have your index.js file at the root of your project, but heroku's error says that the module cannot be found. Then, the problem you are having might be due to GIT.

如果您的项目根目录中有index.js文件,但heroku的错误表明无法找到该模块。然后,您遇到的问题可能是由于GIT。

How can we make sure this is the case? Well, your git repo might not be adding your index.js file to commits nor pushing it to heroku. You can verify this by looking at the files that git is watching in your local repo with the following command:

我们怎样才能确定是这种情况?好吧,你的git repo可能没有将你的index.js文件添加到提交中,也没有将它推送到heroku。您可以使用以下命令查看git在本地存储库中观看的文件来验证这一点:

git ls-files

Your index.js file should be listed. If not, then your file is being ignored.

应列出您的index.js文件。如果没有,那么您的文件将被忽略。

Solution: Force add your file.

解决方案:强制添加您的文件。

git add --force ./index.js

Now you can commit and push to heroku and you should be up and running.

现在你可以提交并推送到heroku,你应该启动并运行。

This might also be the case when having your index file inside a dist directory or src (app/dist/index.js or app/src/index.js).

将索引文件放在dist目录或src(app / dist / index.js或app / src / index.js)中时也可能出现这种情况。

#1


4  

Add relative path for index.js file as bellow

为index.js文件添加相对路径,如下所示

web: node ./index.js

#2


2  

If you do have your index.js file at the root of your project, but heroku's error says that the module cannot be found. Then, the problem you are having might be due to GIT.

如果您的项目根目录中有index.js文件,但heroku的错误表明无法找到该模块。然后,您遇到的问题可能是由于GIT。

How can we make sure this is the case? Well, your git repo might not be adding your index.js file to commits nor pushing it to heroku. You can verify this by looking at the files that git is watching in your local repo with the following command:

我们怎样才能确定是这种情况?好吧,你的git repo可能没有将你的index.js文件添加到提交中,也没有将它推送到heroku。您可以使用以下命令查看git在本地存储库中观看的文件来验证这一点:

git ls-files

Your index.js file should be listed. If not, then your file is being ignored.

应列出您的index.js文件。如果没有,那么您的文件将被忽略。

Solution: Force add your file.

解决方案:强制添加您的文件。

git add --force ./index.js

Now you can commit and push to heroku and you should be up and running.

现在你可以提交并推送到heroku,你应该启动并运行。

This might also be the case when having your index file inside a dist directory or src (app/dist/index.js or app/src/index.js).

将索引文件放在dist目录或src(app / dist / index.js或app / src / index.js)中时也可能出现这种情况。