我跟随Brad Traversys Guide使用React.js,Redux.js,Node.js,Express.js和MongoDB以及create-react-app和Mlab构建了这个基本的MERN Stack App。该应用程序可以在我的本地服务器上正常运行,没有任何错误,但是我无法将其部署到Heroku。
我使用Heroku CLI部署了该应用程序,并收到消息:
deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/salty-temple-63286.git
d4eeb21..473c3c0 master -> master
但是当我visit my app时,出现以下错误消息:
应用程序错误应用程序和页面中发生错误 无法送达。如果您是应用程序所有者,请检查您的日志 有关详细信息。您可以使用以下命令从Heroku CLI执行此操作 heroku日志--tail
以下是日志:
$ heroku logs --tail
2019-01-04T04:03:49.583742+00:00 app[web.1]: at require
(internal/modules/cjs/helpers.js:22:18)
2019-01-04T04:03:49.583743+00:00 app[web.1]: at Object.<anonymous> (/app/routes/api/items.js:5:14)
2019-01-04T04:03:49.583745+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:689:30)
2019-01-04T04:03:49.583746+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
2019-01-04T04:03:49.583748+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:599:32)
2019-01-04T04:03:49.583749+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
2019-01-04T04:03:49.583751+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:530:3)
2019-01-04T04:03:49.583752+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:637:17)
2019-01-04T04:03:49.583753+00:00 app[web.1]: at require
(internal/modules/cjs/helpers.js:22:18)
2019-01-04T04:03:49.583755+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:5:15)
2019-01-04T04:03:49.583756+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:689:30)
2019-01-04T04:03:49.583758+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
2019-01-04T04:03:49.583759+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:599:32)
2019-01-04T04:03:49.595916+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-01-04T04:03:49.596791+00:00 app[web.1]: npm ERR! errno 1
2019-01-04T04:03:49.598998+00:00 app[web.1]: npm ERR! mern-todo-list@1.0.0 start: `node server.js`
2019-01-04T04:03:49.599272+00:00 app[web.1]: npm ERR! Exit status 1
2019-01-04T04:03:49.599660+00:00 app[web.1]: npm ERR!
2019-01-04T04:03:49.599892+00:00 app[web.1]: npm ERR! Failed at the mern-todo-list@1.0.0 start script.
2019-01-04T04:03:49.600155+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-01-04T04:03:49.606443+00:00 app[web.1]:
2019-01-04T04:03:49.606744+00:00 app[web.1]: npm ERR! A
complete log of this run can be found in:
2019-01-04T04:03:49.606972+00:00 app[web.1]: npm ERR!
/app/.npm/_logs/2019-01-04T04_03_49_602Z-debug.log
2019-01-04T04:03:49.702411+00:00 heroku[web.1]: State changed from starting to crashed
2019-01-04T04:03:49.684411+00:00 heroku[web.1]: Process
exited with status 1
2019-01-04T04:31:16.938787+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=salty-temple-63286.herokuapp.com request_id=f0b7eaee-06e7-4967-a074-59aa0e9a8049 fwd="70.178.46.128" dyno= connect= service= status=503 bytes= protocol=https
2019-01-04T04:31:17.235532+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=salty-temple-63286.herokuapp.com request_id=9b2a211f-3884-4d98-893f-6564e6acd763 fwd="70.178.46.128" dyno= connect= service= status=503 bytes= protocol=https
2019-01-04T04:49:22.138341+00:00 heroku[web.1]: State changed from crashed to starting
2019-01-04T04:49:33.868352+00:00 heroku[web.1]: Starting process with command `npm start`
2019-01-04T04:49:36.661765+00:00 app[web.1]: internal/modules/cjs/loader.js:583
2019-01-04T04:49:36.661802+00:00 app[web.1]: throw err;
2019-01-04T04:49:36.661805+00:00 app[web.1]: ^
2019-01-04T04:49:36.661806+00:00 app[web.1]:
2019-01-04T04:49:36.661808+00:00 app[web.1]: Error: Cannot find module '../../models/Item'
2019-01-04T04:49:36.661810+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
2019-01-04T04:49:36.661812+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:507:25)
2019-01-04T04:49:36.661814+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:637:17)
2019-01-04T04:49:36.661816+00:00 app[web.1]: at require
(internal/modules/cjs/helpers.js:22:18)
2019-01-04T04:49:36.661817+00:00 app[web.1]: at Object.<anonymous> (/app/routes/api/items.js:5:14)
2019-01-04T04:49:36.661819+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:689:30)
2019-01-04T04:49:36.661821+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
2019-01-04T04:49:36.661822+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:599:32)
2019-01-04T04:49:36.661824+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
2019-01-04T04:49:36.661826+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:530:3)
2019-01-04T04:49:36.661827+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:637:17)
2019-01-04T04:49:36.661829+00:00 app[web.1]: at require
(internal/modules/cjs/helpers.js:22:18)
2019-01-04T04:49:36.661830+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:5:15)
2019-01-04T04:49:36.661832+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:689:30)
2019-01-04T04:49:36.661834+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
2019-01-04T04:49:36.661836+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:599:32)
2019-01-04T04:49:36.671225+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-01-04T04:49:36.671934+00:00 app[web.1]: npm ERR! errno 1
2019-01-04T04:49:36.675221+00:00 app[web.1]: npm ERR! mern-todo-list@1.0.0 start: `node server.js`
2019-01-04T04:49:36.675350+00:00 app[web.1]: npm ERR! Exit status 1
2019-01-04T04:49:36.675658+00:00 app[web.1]: npm ERR!
2019-01-04T04:49:36.675859+00:00 app[web.1]: npm ERR! Failed at the mern-todo-list@1.0.0 start script.
2019-01-04T04:49:36.676063+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-01-04T04:49:36.683266+00:00 app[web.1]:
2019-01-04T04:49:36.683410+00:00 app[web.1]: npm ERR! A
complete log of this run can be found in:
2019-01-04T04:49:36.683500+00:00 app[web.1]: npm ERR!
/app/.npm/_logs/2019-01-04T04_49_36_677Z-debug.log
2019-01-04T04:49:36.746910+00:00 heroku[web.1]: Process
exited with status 1
2019-01-04T05:08:20.000000+00:00 app[api]: Build started by user tony@wheelertechconsulting.com
2019-01-04T05:09:53.657668+00:00 app[api]: Deploy 5dfee3cd by user tony@wheelertechconsulting.com
2019-01-04T05:10:07.043883+00:00 heroku[web.1]: State changed from starting to crashed
2019-01-04T05:10:07.195622+00:00 heroku[web.1]: State changed from crashed to starting
2019-01-04T05:10:23.550457+00:00 heroku[web.1]: Starting process with command `npm start`
2019-01-04T05:10:29.715690+00:00 app[web.1]: internal/modules/cjs/loader.js:583
2019-01-04T05:10:29.715709+00:00 app[web.1]: throw err;
2019-01-04T05:10:29.715711+00:00 app[web.1]: ^
2019-01-04T05:10:29.715712+00:00 app[web.1]:
2019-01-04T05:10:29.715714+00:00 app[web.1]: Error: Cannot find module '../../models/Item'
2019-01-04T05:10:29.715717+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
2019-01-04T05:10:29.715719+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:507:25)
2019-01-04T05:10:29.715721+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:637:17)
2019-01-04T05:10:29.715723+00:00 app[web.1]: at require
(internal/modules/cjs/helpers.js:22:18)
2019-01-04T05:10:29.715725+00:00 app[web.1]: at Object.<anonymous> (/app/routes/api/items.js:5:14)
2019-01-04T05:10:29.715726+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:689:30)
2019-01-04T05:10:29.715728+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
2019-01-04T05:10:29.715729+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:599:32)
2019-01-04T05:10:29.715731+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
2019-01-04T05:10:29.715732+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:530:3)
2019-01-04T05:10:29.715734+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:637:17)
2019-01-04T05:10:29.715735+00:00 app[web.1]: at require
(internal/modules/cjs/helpers.js:22:18)
2019-01-04T05:10:29.715737+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:5:15)
2019-01-04T05:10:29.715738+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:689:30)
2019-01-04T05:10:29.715740+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
2019-01-04T05:10:29.715741+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:599:32)
2019-01-04T05:10:29.729403+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-01-04T05:10:29.730408+00:00 app[web.1]: npm ERR! errno 1
2019-01-04T05:10:29.733076+00:00 app[web.1]: npm ERR! mern-todo-list@1.0.0 start: `node server.js`
2019-01-04T05:10:29.733443+00:00 app[web.1]: npm ERR! Exit status 1
2019-01-04T05:10:29.734184+00:00 app[web.1]: npm ERR!
2019-01-04T05:10:29.734545+00:00 app[web.1]: npm ERR! Failed at the mern-todo-list@1.0.0 start script.
2019-01-04T05:10:29.734884+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-01-04T05:10:29.776964+00:00 app[web.1]:
2019-01-04T05:10:29.777279+00:00 app[web.1]: npm ERR! A
complete log of this run can be found in:
2019-01-04T05:10:29.777445+00:00 app[web.1]: npm ERR!
/app/.npm/_logs/2019-01-04T05_10_29_737Z-debug.log
2019-01-04T05:10:29.867624+00:00 heroku[web.1]: State changed from starting to crashed
2019-01-04T05:10:29.850311+00:00 heroku[web.1]: Process
exited with status 1
2019-01-04T05:11:20.716383+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=salty-temple-63286.herokuapp.com request_id=6ec0a43b-6e8a-45a8-ae8c-f4ced564fec5 fwd="70.178.46.128" dyno= connect= service= status=503 bytes= protocol=https
以下是我档案中的一些相关摘录: 从server.js:
// Serve static assets if in production
if (process.env.NODE_ENV === "production") {
// Set static folder
app.use(express.static("client/build"));
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
}
和
// DB config
const db = require("./config/keys").mongoURI;
我的服务器端.gitignore
node_modules/
package-lock.json
config/keys_dev.js
我的服务器端package.json:
{
"name": "mern-todo-list",
"version": "1.0.0",
"description": "A todo list built with the mern stack",
"main": "server.js",
"scripts": {
"client-install": "npm i --prefix client",
"start": "node server.js",
"server": "nodemon server.js",
"client": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
},
"author": "Tony Wheeler",
"license": "MIT",
"dependencies": {
"concurrently": "^4.1.0",
"express": "^4.16.4",
"mongoose": "^5.4.1"
},
"devDependencies": {
"nodemon": "^1.18.9"
}
}
我的config / keys.js:
if (process.env.NODE_ENV === "production") {
module.exports = require("./keys_prod");
} else {
module.exports = require("./keys_dev");
}
我的config / keys_prod.js
module.exports = {
mongoURI: process.env.MONGO_URI
};
在我的heroku仪表板中,我将配置变量配置为:
MONGO_URI mongodb:// myusername:mypassword@ds147344.mlab.com:47344 / mern_todo
正如我所说,“我的应用”可与本地服务器上的数据库一起使用,但不适用于heroku。
以下是Github上的完整代码:https://github.com/twheelertech/mern-todo-list
我以前已经成功将MERN部署到heroku,但是到目前为止没有遇到此错误。
有人可以帮助我了解如何解决此问题吗?
答案 0 :(得分:0)
错误:找不到模块'../../ models / Item'
您可能正在使用宽容导入框的Mac上进行开发。
该文件名为item.js
,Linux系统找不到Item.js
。确保您的机壳与导入语句匹配。对此有警告: