gpt4 book ai didi

node.js - 我的 meern 应用程序无法在 heroku 上运行。我该如何修复这个错误?

转载 作者:太空宇宙 更新时间:2023-11-04 00:02:22 24 4
gpt4 key购买 nike

我关注了Brad Traversys Guide使用 React.js、Redux.js、Node.js、Express.js 和 MongoDB 以及 create-react-app 和 Mlab 构建这个基本的 MERN Stack 应用程序。该应用程序在我的本地服务器上运行良好,没有错误,但是我在将其部署到 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我收到以下错误消息:

Application error An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command heroku logs --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,但之前没有遇到过这个错误。

谁能帮我理解如何解决这个问题?

最佳答案

Error: Cannot find module '../../models/Item'

您可能正在使用导入外壳的 Mac 上进行开发。

该文件名为 item.js,Linux 系统找不到 Item.js。确保您的外壳与导入声明相符。有一个 eslint 警告:

https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-unresolved.md#casesensitive

关于node.js - 我的 meern 应用程序无法在 heroku 上运行。我该如何修复这个错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54033429/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com