简体   繁体   English

heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" | 在 Heroku 中部署时发生错误

[英]heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" | Error occurs when deployed in Heroku

I am currently taking the MERN stack e-commerce course from Brad and Bassir in Udemy.我目前正在 Udemy 的 Brad 和 Bassir 学习 MERN 堆栈电子商务课程。 When I deployed in Heroku, I got this error.当我在 Heroku 中部署时,出现此错误。 I don't know how to resolve it.我不知道如何解决。

These are the logs when I run heroku logs --tail command这些是我运行 heroku logs --tail 命令时的日志

2021-10-15T17:50:42.000000+00:00 app[api]: Build started by user roopeshsaravanan.dev@gmail.com
2021-10-15T17:53:37.636364+00:00 app[api]: Deploy 90321645 by user roopeshsaravanan.dev@gmail.com
2021-10-15T17:53:37.636364+00:00 app[api]: Release v19 created by user roopeshsaravanan.dev@gmail.com
2021-10-15T17:53:39.000000+00:00 app[api]: Build succeeded
2021-10-15T17:53:43.122703+00:00 heroku[web.1]: State changed from crashed to starting
2021-10-15T17:53:50.219102+00:00 heroku[web.1]: Starting process with command `node backend/server.js`
2021-10-15T17:53:51.386374+00:00 app[web.1]: internal/modules/cjs/loader.js:905
2021-10-15T17:53:51.386389+00:00 app[web.1]: throw err;
2021-10-15T17:53:51.386390+00:00 app[web.1]: ^
2021-10-15T17:53:51.386390+00:00 app[web.1]:
2021-10-15T17:53:51.386390+00:00 app[web.1]: Error: Cannot find module 'nodemon'
2021-10-15T17:53:51.386390+00:00 app[web.1]: Require stack:
2021-10-15T17:53:51.386391+00:00 app[web.1]: - /app/backend/models/userModel.js
2021-10-15T17:53:51.386391+00:00 app[web.1]: - /app/backend/middleware/authMiddleware.js
2021-10-15T17:53:51.386391+00:00 app[web.1]: - /app/backend/routes/productRoutes.js
2021-10-15T17:53:51.386391+00:00 app[web.1]: - /app/backend/server.js
2021-10-15T17:53:51.386392+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
2021-10-15T17:53:51.386392+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:746:27)
2021-10-15T17:53:51.386392+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:974:19)
2021-10-15T17:53:51.386393+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:93:18)
2021-10-15T17:53:51.386393+00:00 app[web.1]: at Object.<anonymous> (/app/backend/models/userModel.js:4:19)
2021-10-15T17:53:51.386393+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1085:14)
2021-10-15T17:53:51.386393+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
2021-10-15T17:53:51.386394+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:950:32)
2021-10-15T17:53:51.386394+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:790:12)
2021-10-15T17:53:51.386394+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:974:19) {
2021-10-15T17:53:51.386395+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2021-10-15T17:53:51.386395+00:00 app[web.1]: requireStack: [
2021-10-15T17:53:51.386395+00:00 app[web.1]: '/app/backend/models/userModel.js',
2021-10-15T17:53:51.386395+00:00 app[web.1]: '/app/backend/middleware/authMiddleware.js',
2021-10-15T17:53:51.386396+00:00 app[web.1]: '/app/backend/routes/productRoutes.js',
2021-10-15T17:53:51.386396+00:00 app[web.1]: '/app/backend/server.js'
2021-10-15T17:53:51.386396+00:00 app[web.1]: ]
2021-10-15T17:53:51.386396+00:00 app[web.1]: }
2021-10-15T17:53:51.503588+00:00 heroku[web.1]: Process exited with status 1
2021-10-15T17:53:51.589143+00:00 heroku[web.1]: State changed from starting to crashed
2021-10-15T17:54:14.240609+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=largegreen.herokuapp.com request_id=9000e675-5c48-4ef5-bcd0-9e968668542a fwd="42.111.162.194" dyno= connect= service= status=503 bytes= protocol=https
2021-10-15T17:54:16.260707+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=largegreen.herokuapp.com request_id=d645168d-e122-435d-bd5f-2634f6a66f28 fwd="42.111.162.194" dyno= connect= service= status=503 bytes= protocol=https
2021-10-15T17:54:24.212721+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=largegreen.herokuapp.com request_id=35ab40a6-e42d-4b54-83a1-9b5526929d38 fwd="42.111.162.194" dyno= connect= service= status=503 bytes= protocol=https
2021-10-15T17:54:25.252707+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=largegreen.herokuapp.com request_id=65c7660f-9c13-42af-92f3-f358830bb993 fwd="42.111.162.194" dyno= connect= service= status=503 bytes= protocol=https
2021-10-15T18:16:35.058685+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=largegreen.herokuapp.com request_id=e3380719-6b36-4db6-a705-e1ea7eea88dc fwd="42.111.162.194" dyno= connect= service= status=503 bytes= protocol=https
2021-10-15T18:16:36.046104+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=largegreen.herokuapp.com request_id=6dd2cf7e-ca8c-481a-94b6-70f3ed0d3683 fwd="42.111.162.194" dyno= connect= service= status=503 bytes= protocol=https

1. Try to set up this type of directory Structure 1.尝试设置这种类型的目录结构

|__client/  THIS IS EVERYTHING FROM THE REACT SIDE 
    |__ node_modules/
        |__ tons of stuff...
    |__ public/
        |__ index.html
        |__ favicon.ico
        |__ etc.
    |__ src/
        |__ index.js
        |__ main/
            |__ App.js
            |__ etc.
|__ models/
    |__ user.js
    |__ todo.js
    |__ etc.
|__ node_modules/
    |__ stuff...
|__ routes
    |__ userRoutes.js
    |__ todoRoutes.js
    |__ etc.
|__ .gitignore
|__ package.json
|__ server.js
|__ etc.

2. Add this Middleware 2. 添加这个中间件

// ... Other imports
const path = require("path");

// Other app.use middleware
app.use(express.static(path.join(__dirname, "client", "build")));

// Right before your app.listen(), add this:
app.get("*", (req, res) => {
  res.sendFile(path.join(__dirname, "client", "build", "index.html"));
});

app.listen(...);

3. Add a proxy to the client's package.json 3.在客户端的package.json添加代理

"proxy": "http://localhost:8000"

So, your package.json file looks like...所以,你的package.json文件看起来像......

{
    "name": "client",
    "version": "0.1.0",
    "private": true,
    "dependencies": {
        "axios": "^0.17.1",
        "react": "^16.2.0",
        "react-dom": "^16.2.0",
        "react-scripts": "1.0.17"
    },
    "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test --env=jsdom",
        "eject": "react-scripts eject"
    },
    "proxy": "http://localhost:8000"
}

4. Setting environment variables on the website: 4.在网站上设置环境变量:

A. Open your app in Heroku
B. Go to "Settings"
C. Click "Reveal Config Vars"
D. Add a new variable and click "Add". Done!
E. Your port has to look like:- process.env.PORT || 8000

Your Port looks like this:-您的端口如下所示:-

const port = process.env.PORT || 8000;
.
.
.
app.listen(port);

5. Set up MongoDB Atlas IP access control 5.设置MongoDB Atlas IP访问控制

Next, you'll need to whitelist your IP address so that you can access your cluster.接下来,您需要将您的 IP 地址列入白名单,以便您可以访问您的集群。 Go to Network Access on the navigation menu, and Add IP Address.转到导航菜单上的网络访问,然后添加 IP 地址。 You can either Add Your Current IP Address or Allow Access from Anywhere .您可以添加您当前的 IP 地址或允许从任何地方访问 Confirm your choice.确认您的选择。

For any projects deployed through Heroku, you'll have to select Allow Access from Anywhere.对于通过 Heroku 部署的任何项目,您必须选择 Allow Access from Anywhere。 This is because Heroku uses Dynamic IPs.这是因为 Heroku 使用动态 IP。 While this isn't the most secure option, it is fine for now.虽然这不是最安全的选择,但目前还可以。

6. Add this scripts start heroku-postbuild and engines 6.添加这个脚本start heroku-postbuildengines

After all this, your server's package.json should look something like this: In the terminal, type node -v .毕竟,您服务器的package.json应该如下所示: 在终端中,输入node -v It should spit out the version of Node.js you're using.它应该会显示您正在使用的 Node.js 版本。 add this version in the "engines": "14.17.5""engines": "14.17.5"添加此版本"engines": "14.17.5"

{
    "name": "mern-to-heroku",
    "version": "1.0.0",
    "main": "server.js",
    "license": "MIT",
    "dependencies": {
        "body-parser": "^1.18.2",
        "express": "^4.16.2",
        "mongoose": "^4.13.6",
        "morgan": "^1.9.0"
    },
    "scripts": {
        "start": "node server.js",
        "heroku-postbuild": "cd client && npm install --only=dev && npm install && npm run build"
    },
    "engines": {
        "node": "14.17.5"
    }
}

You should now be all set up to deploy your site through Heroku!您现在应该已经准备好通过 Heroku 部署您的站点了!

I tried to deploy be myself and got the same error.我试图部署我自己并得到同样的错误。 Make the port dynamic (most likely process.env.PORT ) and set the correct run command web: npm run start:prod使端口动态(很可能process.env.PORT )并设置正确的运行命令web: npm run start:prod

Source and more info: https://dev.to/rosyshrestha/deploy-nestjs-typescript-app-to-heroku-27e来源和更多信息: https : //dev.to/rosyshrestha/deploy-nestjs-typescript-app-to-heroku-27e

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Heroku 错误:heroku[router]: at=error code=H10 desc=&quot;App crashed&quot; method=GET path=&quot;/&quot;? - Heroku error: heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/"? Heroku[router]: at=error code=H10 desc=”App crashed“ method=GET path=/favicon.ico” - Heroku[router]: at=error code=H10 desc=”App crashed“ method=GET path=/favicon.ico” Heroku 崩溃错误:heroku[router]: at=error code=H10 desc=“App crashed” method=GET path=“/favicon.ico” - Heroku Crash Error: heroku[router]: at=error code=H10 desc=“App crashed” method=GET path=“/favicon.ico” Heroku Node.js错误heroku [路由器]:at =错误代码= H10 desc =“应用程序崩溃”方法=获取路径=“ /” - Heroku Node.js Error heroku[router]: at=error code=H10 desc=“App crashed” method=GET path=“/” Heroku 应用程序崩溃:at=error code=H10 desc=“App crashed” method=GET path=“/” - Heroku application crashed: at=error code=H10 desc=“App crashed” method=GET path=“/” at =错误代码= H10 desc =“应用程序崩溃”方法=获取路径=“ /”将React / Node部署到Heroku时出错 - at=error code=H10 desc=“App crashed” method=GET path=“/” Error Deploying React/Node to Heroku Heroku + node.js错误at =错误代码= H10 desc =“应用程序崩溃”方法= GET路径=“ /” - Heroku + node.js error at=error code=H10 desc=“App crashed” method=GET path=“/” Heroku 节点崩溃:at=error code=H10 desc=&quot;App crashed&quot; method=GET path=&quot;/&quot; - Heroku Node Crash: at=error code=H10 desc="App crashed" method=GET path="/" 为什么我的heroku node.js app给出at = error code = H10 desc =“App crashed”method = GET path =“/”? - Why my heroku node.js app is giving at=error code=H10 desc=“App crashed” method=GET path=“/”? Heroku at=error code=H10 desc="App 崩溃" - Heroku at=error code=H10 desc="App crashed"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM