[英]heroku Error: Cannot find module '/app/index.js'
我正在 Heroku 上托管一个大学项目,我需要托管一个 django 应用程序,它也需要一个 npm 库,但我搜索了很多关于如何执行此操作的方法,最终我以为我掌握了它,但现在我收到了这个错误:
2018-06-14T10:19:22.798022+00:00 app[web.1]: throw err;
2018-06-14T10:19:22.798023+00:00 app[web.1]: ^
2018-06-14T10:19:22.798024+00:00 app[web.1]:
2018-06-14T10:19:22.798026+00:00 app[web.1]: Error: Cannot find module '/app/server.js'
2018-06-14T10:19:22.798028+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:547:15)
2018-06-14T10:19:22.798029+00:00 app[web.1]: at Function.Module._load (module.js:474:25)
2018-06-14T10:19:22.798030+00:00 app[web.1]: at Function.Module.runMain (module.js:693:10)
2018-06-14T10:19:22.798031+00:00 app[web.1]: at startup (bootstrap_node.js:191:16)
2018-06-14T10:19:22.798033+00:00 app[web.1]: at bootstrap_node.js:612:3
这是我的 package.json:
{
"name": "dpl-webtech",
"version": "1.0.0",
"description": "DBL - Webtech Group D24",
"main": "index.js",
"scripts": {
"start": "nf start"
},
"repository": {
"type": "git",
"url": "git+https://github.com/spiderangel123/DPL-WebTech.git"
},
"author": "Ahmad Alsarakbi",
"license": "ISC",
"bugs": {
"url": "https://github.com/spiderangel123/DPL-WebTech/issues"
},
"homepage": "https://github.com/spiderangel123/DPL-WebTech#readme",
"engines": {
"node": "8.11.2",
"npm": "6.1.0"
},
"dependencies": {
"npm": "^6.1.0",
"phantomjs-prebuilt": "^2.1.16"
}
}[![enter image description here][1]][1]
这是我的 procfile:
web: gunicorn DBL.wsgi
web: node ./index.js
我最近遇到了同样的问题,尽管构建成功。
问题不是来自您的项目存储库结构,其中应用程序文件夹将丢失。 Heroku 应用程序包含一个 Procfile,用于指定由应用程序的 dynos 执行的命令。 当你加载你的应用程序时,Heroku 将启动一个 web 进程类型。
我的猜测是您没有 Procfile,也没有定义 Web 进程。
最简单的方法是在项目的根目录添加一个 Procfile。 Procfile 的名称没有扩展名。 在其中添加一个具有以下结构的 Web 进程: <process type>: <command>
对于 NodeJS 应用程序,您通常可以使用以下说明:
web: node dist/server/index.js
您只需要根据您的应用对其进行自定义。
你能分享一下文件结构吗?
当server.js的文件路径不正确时会发生此错误,因此请检查heroku所采用的文件路径是否正确。
你不需要包含 web: node index.js 如果你只需要包含包,但有人提到将它添加到 Procfile 我读到的关于如何在 heroku 中使用 npm 所以我有一个误解,除非我添加它。
我收到此错误,就我而言,这是因为我的服务器启动文件是index.ts
而不是index.js
因为我正在使用打字稿。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.