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

时间:2016-08-18 10:31:03

标签: node.js heroku

我正在尝试在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

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

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

4 个答案:

答案 0 :(得分:4)

  1. 您的index.js文件是否在根目录中?
  2.     web: node ./index.js
    
    1. 您的文件可能嵌套为app/src/index.js
    2.     web: node ./src/index.js
      
      1. 您的index.js是否有大写'我'?它必须是 index.js 而不是Index.js
      2. 如果您执行在项目的根目录中包含 index.js 文件,但 heroku 错误表示无法找到模块。然后,您遇到的问题可能是由于 GIT

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

        git ls-files
        

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

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

        git add --force ./index.js
        

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

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

答案 1 :(得分:3)

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

web: node ./index.js

答案 2 :(得分:0)

我的问题是我的本地开发环境有问题。不知何故...JavaScript 代码被注入到我的应用项目中,而我并没有这样做。

不知道发生了这种情况,Heroku 在我推送期间开始看到错误,例如“找不到 jQuery,即使您在应用程序中使用它”。我就像“什么????,我什至没有使用 jQuery。”然后我在我的项目中重新打开了一个 .js 文件……它就是一个声明 jquery 的 const 变量。所以我说了这么多,请检查您的 VSCode 扩展、您的第三方 npm 包以及与此相关的所有内容,以确保此类事情不会发生在您身上。

答案 3 :(得分:-1)

如果错误仍然发生,请尝试使用:

web: node .
相关问题