node.js - 节点部署到 heroku 失败
问题描述
我正在尝试将基本应用程序部署到 heroku,但出现错误。我已经包括了heroku日志。
2018-08-12T11:19:35.082630+00:00 app[web.1]: Error: Cannot find module '/app/server/server.js'
2018-08-12T11:19:35.082632+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:536:15)
2018-08-12T11:19:35.082634+00:00 app[web.1]: at Function.Module._load (module.js:466:25)
2018-08-12T11:19:35.082635+00:00 app[web.1]: at Function.Module.runMain (module.js:676:10)
2018-08-12T11:19:35.082651+00:00 app[web.1]: at startup (bootstrap_node.js:187:16)
2018-08-12T11:19:35.082653+00:00 app[web.1]: at bootstrap_node.js:608:3
2018-08-12T11:19:35.165790+00:00 heroku[web.1]: State changed from starting to crashed
2018-08-12T11:19:35.168329+00:00 heroku[web.1]: State changed from crashed to starting
2018-08-12T11:19:38.372891+00:00 heroku[web.1]: Starting process with command `node server/server.js`
2018-08-12T11:19:40.669347+00:00 heroku[web.1]: Process exited with status 1
2018-08-12T11:19:40.685006+00:00 heroku[web.1]: State changed from starting to crashed
2018-08-12T11:19:40.573913+00:00 app[web.1]: module.js:538
2018-08-12T11:19:40.573936+00:00 app[web.1]: throw err;
2018-08-12T11:19:40.573938+00:00 app[web.1]: ^
2018-08-12T11:19:40.573940+00:00 app[web.1]:
2018-08-12T11:19:40.573942+00:00 app[web.1]: Error: Cannot find module '/app/server/server.js'
2018-08-12T11:19:40.573943+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:536:15)
2018-08-12T11:19:40.573945+00:00 app[web.1]: at Function.Module._load (module.js:466:25)
2018-08-12T11:19:40.573947+00:00 app[web.1]: at Function.Module.runMain (module.js:676:10)
2018-08-12T11:19:40.573949+00:00 app[web.1]: at startup (bootstrap_node.js:187:16)
2018-08-12T11:19:40.573951+00:00 app[web.1]: at bootstrap_node.js:608:3
我已经包含了这样的启动脚本
"scripts": {
"start": "node server/server.js",
"test": "export NODE_ENV=test || SET \"NODE_ENV=test\" && mocha \"./{,!(node_modules)/**/}*.test.js\""
},
请告诉我我错过了什么。我还附上了我的根目录文件夹图像。图片
解决方案
只要您已经在使用 Procfile,您就可以在那里指定:
web: node server/server.js
默认情况下,Heroku 首先查看 Profice 以启动服务器。然后它才会查看 package.json 的启动脚本。
推荐阅读
- fluent-bit - Fluentbit rewrite_tag 不适用于 JSON 数组
- pyarrow - 如何将 ndarray 写入和读取到 pyarrow 等离子商店?
- java - 通过后映射将数组从 Spring Boot 传递给 Reactjs 仅返回第一个对象
- html - 如何在 PC 视图上将我的卡作为二进制组
- android-studio - 从 android studio dev env 连接到 Android 模拟器。在 Virtualbox 虚拟机中
- php - PHP中电子表格的时间差异
- python - 将熊猫 0.25.3 升级到 1.3.2
- javascript - 如何从嵌套的对象数组中获取每个父级的值
- javascript - 如何通过 querySelectorAll() 选择所有元素
- caching - 使用 kaniko 构建多阶段图像时的缓存问题