【问题标题】:Heroku npm start starts from different locationHeroku npm start 从不同的位置开始
【发布时间】:2020-11-12 06:53:20
【问题描述】:

我有一个功能齐全的 NodeJs 应用程序,其中捆绑了一个子模块,因此子模块是主应用程序,另一个节点项目是建立在它之上的。

我想从外部应用程序运行子模块(内部应用程序)。听起来可能很奇怪,但这确实是我想要实现的。 当我在本地环境中运行它时它运行良好,但我无法让它在 Heroku 上运行。

我在本地使用命令运行它:heroku local web

我的 Procfile:web: npm run startwithouteslint

我的外包装.json:

{
  "name": "chatgine-pension",
  "version": "1.0.0",
  "description": "Chatgine-pension application",
  "engines": {
    "node": "10.x"
  },
  "main": "chatiety-engine/index.js",
  "scripts": {
    "startwithouteslint": "npm run startwithouteslint --prefix chatiety-engine",
    "start": "eslint \"**/*.js\" && npm start --prefix chatiety-engine",
    "test": "eslint \"**/*.js\" && mocha test --recursive --exit",
    "coverage": "eslint \"**/*.js\" && nyc --reporter=text mocha test --recursive --exit"
  },
  "dependencies": {},
  "devDependencies": {},
  "repository": {},
  "keywords": [],
  "license": "custom"
}

我的内部 package.json(在 chatiety-engine 文件夹内):

{
  "name": "chatiety-engine",
  "version": "1.0.0",
  "description": "Chatiety-engine application",
  "engines": {
    "node": "10.x"
  },
  "main": "index.js",
  "scripts": {
    "startwithouteslint": "node index.js",
    "start": "eslint \"**/*.js\" && node index.js",
    "test": "eslint \"**/*.js\" && mocha test --recursive --exit",
    "coverage": "eslint \"**/*.js\" && nyc --reporter=text mocha test --recursive --exit"
  },
  "dependencies": {},
  "devDependencies": {},
  "repository": {},
  "keywords": [],
  "license": "custom"
}

项目结构:

来自 Heroku 的错误信息:

2019-11-25T16:43:45.727225+00:00 heroku[web.1]: Starting process with command `npm run startwithouteslint`
2019-11-25T16:43:48.223968+00:00 app[web.1]: 
2019-11-25T16:43:48.223991+00:00 app[web.1]: > chatgine-pension@1.0.0 startwithouteslint /app
2019-11-25T16:43:48.223993+00:00 app[web.1]: > npm run startwithouteslint --prefix chatiety-engine
2019-11-25T16:43:48.223995+00:00 app[web.1]: 
2019-11-25T16:43:48.559728+00:00 app[web.1]: npm ERR! code ENOENT
2019-11-25T16:43:48.560276+00:00 app[web.1]: npm ERR! syscall open
2019-11-25T16:43:48.560632+00:00 app[web.1]: npm ERR! path /app/chatiety-engine/package.json
2019-11-25T16:43:48.563785+00:00 app[web.1]: npm ERR! errno -2
2019-11-25T16:43:48.563789+00:00 app[web.1]: npm ERR! enoent ENOENT: no such file or directory, open '/app/chatiety-engine/package.json'
2019-11-25T16:43:48.563792+00:00 app[web.1]: npm ERR! enoent This is related to npm not being able to find a file.
2019-11-25T16:43:48.563793+00:00 app[web.1]: npm ERR! enoent 
2019-11-25T16:43:48.570839+00:00 app[web.1]: 
2019-11-25T16:43:48.571073+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-11-25T16:43:48.571158+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2019-11-25T16_43_48_563Z-debug.log
2019-11-25T16:43:48.578800+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-11-25T16:43:48.579173+00:00 app[web.1]: npm ERR! errno 254
2019-11-25T16:43:48.580465+00:00 app[web.1]: npm ERR! chatgine-pension@1.0.0 startwithouteslint: `npm run startwithouteslint --prefix chatiety-engine`
2019-11-25T16:43:48.580626+00:00 app[web.1]: npm ERR! Exit status 254
2019-11-25T16:43:48.580875+00:00 app[web.1]: npm ERR! 
2019-11-25T16:43:48.581043+00:00 app[web.1]: npm ERR! Failed at the chatgine-pension@1.0.0 startwithouteslint script.
2019-11-25T16:43:48.581209+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-11-25T16:43:48.587148+00:00 app[web.1]: 
2019-11-25T16:43:48.587357+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-11-25T16:43:48.587493+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2019-11-25T16_43_48_581Z-debug.log
2019-11-25T16:43:48.666923+00:00 heroku[web.1]: State changed from starting to crashed
2019-11-25T16:43:48.642599+00:00 heroku[web.1]: Process exited with status 254

Heroku 似乎在路径的开头附加了 /app,但我不知道为什么,以及在哪里可以关闭它。

编辑:我能够列出 Heroku 使用的所有环境变量,其中两个很可能导致问题:

PWD=/app
HOME=/app

到目前为止一切顺利,但我无法覆盖这些环境。变量。你知道我怎样才能做到这一点吗?

提前感谢您的帮助!

【问题讨论】:

  • 我还没有找到解决方案,但我发现,如果你将代码推送到 Heroku 远程,Heroku 可以处理子模块,但它不能处理来自其他 git repos 的子模块。因此,将我的代码推送到 Heroku 远程使我的应用程序正常工作,但从长远来看,我想将 Heroku 与我自己的 git 存储库连接起来,所以我仍在等待和寻找解决方案。我不会放弃:)

标签: node.js heroku


【解决方案1】:

我遇到了同样的问题。只要意识到我的代码崩溃了。您必须修复代码中的错误,然后此消息“npm run startwithouteslint”将消失。您可以在终端中运行“npm run start”,一些错误线索将显示在屏幕上。

【讨论】:

  • 正如他所说:It works fine when I run it in a local environment, but I can not make it work on Heroku. 看起来这没有帮助
猜你喜欢
  • 1970-01-01
  • 2020-12-06
  • 2021-11-07
  • 2015-09-08
  • 2017-05-02
  • 2016-03-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多