繁体   English   中英

我无法在 Heroku 中部署我的 Node.js 应用程序“找不到模块”

[英]I can't deploy my Node.js app in Heroku "module not found"

我几乎尝试了所有方法,但无法部署我的应用程序。 这是我收到的最后一条错误消息:

2021-10-19T18:52:01.657189+00:00 app[web.1]: Error: Cannot find module '/app/index.js'
2021-10-19T18:52:01.657190+00:00 app[web.1]: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
2021-10-19T18:52:01.657190+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:778:27)
2021-10-19T18:52:01.657191+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
2021-10-19T18:52:01.657191+00:00 app[web.1]: at node:internal/main/run_main_module:17:47 {
2021-10-19T18:52:01.657191+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2021-10-19T18:52:01.657192+00:00 app[web.1]: requireStack: []
2021-10-19T18:52:01.657192+00:00 app[web.1]: }
2021-10-19T18:52:01.815218+00:00 heroku[web.1]: Process exited with status 1
2021-10-19T18:52:01.959414+00:00 heroku[web.1]: State changed from starting to crashed
2021-10-19T18:52:20.583737+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=bdescondida.herokuapp.com request_id=76e9c4c9-f807-4175-98af-8d37d193e0eb fwd="201.241.70.182" dyno= connect= service= status=503 bytes= protocol=https
2021-10-19T18:52:20.890660+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=bdescondida.herokuapp.com request_id=d838b422-8c4c-4ed1-bbb2-159fc5c8bd55 fwd="201.241.70.182" dyno= connect= service= status=503 bytes= protocol=https
2021-10-19T18:53:02.257318+00:00 app[api]: Starting process with command `npm start npm start` by user javiermaciasa@icloud.com
2021-10-19T18:53:05.317845+00:00 heroku[run.7095]: State changed from starting to up
2021-10-19T18:53:05.478585+00:00 heroku[run.7095]: Awaiting client
2021-10-19T18:53:05.516229+00:00 heroku[run.7095]: Starting process with command `npm start npm start`
2021-10-19T18:53:09.369175+00:00 heroku[run.7095]: Process exited with status 1
2021-10-19T18:53:09.431811+00:00 heroku[run.7095]: State changed from up to complete
2021-10-19T18:53:44.609047+00:00 app[api]: Starting process with command `npm start` by user javiermaciasa@icloud.com
2021-10-19T18:53:47.178029+00:00 heroku[run.3836]: State changed from starting to up
2021-10-19T18:53:47.188605+00:00 heroku[run.3836]: Awaiting client
2021-10-19T18:53:47.225322+00:00 heroku[run.3836]: Starting process with command `npm start`
2021-10-19T18:53:50.966149+00:00 heroku[run.3836]: Process exited with status 1
2021-10-19T18:53:51.019671+00:00 heroku[run.3836]: State changed from up to complete

这是我的应用程序的 GitHub 存储库: https : //github.com/javiermaciasa/bdescondida

我的应用程序在本地主机上工作,几乎没有问题,只是我知道它有错误。

所以我访问了 git repo 并发现了你构建文件的方式

然后检查你的 package.json 并发现错误

您当前的 package.json

{
  "name": "bdescondida",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "nodemon src/",
    "start": "index.js"
  }

Heroku 通过运行来启动你的包

npm start

在你的情况下是指

索引.js

但是该文件的位置在您的./src/index.js

长话短说指导您的启动脚本路径指向正确的 Dir

编辑你的 package.js

{
  "name": "bdescondida",
  "version": "1.0.0",
  "description": "",
  "main": "./src/index.js",
  "scripts": {
    "dev": "nodemon src/",
    "start": "./src/index.js"
  }

原因是在您的本地机器或 vsode 上工作是因为 nodemon 也在读取 src DIR。

暂无
暂无

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

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