【问题标题】:Need help understanding how to deploy a MERN app to gcloud app engine需要帮助了解如何将 MERN 应用部署到 gcloud 应用引擎
【发布时间】:2020-07-29 19:23:55
【问题描述】:

我正在尝试将 MERN 应用部署到 gcloud 应用引擎实例。

当我部署它并查看日志时,它在启动服务器脚本中抱怨 nodemon。我认为该应用程序不会在构建过程中运行,并且这些脚本是用于开发的。

这是错误:

2020-07-29 17:31:27 default[20200729t103017]  [0] Error: spawn nodemon ENOENT
2020-07-29 17:31:27 default[20200729t103017]  [0]     at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
2020-07-29 17:31:27 default[20200729t103017]  [0]     at onErrorNT (internal/child_process.js:415:16)
2020-07-29 17:31:27 default[20200729t103017]  [0]     at process._tickCallback (internal/process/next_tick.js:63:19)
2020-07-29 17:31:27 default[20200729t103017]  [0]     at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
2020-07-29 17:31:27 default[20200729t103017]  [0]     at startup (internal/bootstrap/node.js:283:19)
2020-07-29 17:31:27 default[20200729t103017]  [0]     at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
2020-07-29 17:31:27 default[20200729t103017]  [0] Emitted 'error' event at:
2020-07-29 17:31:27 default[20200729t103017]  [0]     at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)
2020-07-29 17:31:27 default[20200729t103017]  [0]     at onErrorNT (internal/child_process.js:415:16)
2020-07-29 17:31:27 default[20200729t103017]  [0]     [... lines matching original stack trace ...]
2020-07-29 17:31:27 default[20200729t103017]  [0]     at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
2020-07-29 17:31:28 default[20200729t103017]  [0] npm ERR! code ELIFECYCLE
2020-07-29 17:31:28 default[20200729t103017]  [0] npm ERR! errno 1
2020-07-29 17:31:28 default[20200729t103017]  [0] npm ERR! ddd@0.1.0 start-server: `cross-env NODE_ENV=development nodemon server/app.js`
2020-07-29 17:31:28 default[20200729t103017]  [0] npm ERR! Exit status 1
2020-07-29 17:31:28 default[20200729t103017]  [0] npm ERR!
2020-07-29 17:31:28 default[20200729t103017]  [0] npm ERR! Failed at the ddd@0.1.0 start-server script.
2020-07-29 17:31:28 default[20200729t103017]  [0] npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-07-29 17:31:28 default[20200729t103017]  [0]
2020-07-29 17:31:28 default[20200729t103017]  [0] npm ERR! A complete log of this run can be found in:
2020-07-29 17:31:28 default[20200729t103017]  [0] npm ERR!     /root/.npm/_logs/2020-07-29T17_31_28_004Z-debug.log
2020-07-29 17:31:28 default[20200729t103017]  [0] npm run start-server exited with code 1
2020-07-29 17:31:28 default[20200729t103017]  --> Sending SIGTERM to other processes..
2020-07-29 17:31:28 default[20200729t103017]  [1] npm run start-front exited with code SIGTERM

前端包.json:

{
    "name": "ddd",
    "version": "0.1.0",
    "private": true,
    "dependencies": {
        "@testing-library/jest-dom": "^4.2.4",
        "@testing-library/react": "^9.5.0",
        "@testing-library/user-event": "^7.2.1",
        "body-parser": "^1.19.0",
        "compression": "^1.7.4",
        "concurrently": "^5.2.0",
        "cookie-parser": "^1.4.5",
        "cors": "^2.8.5",
        "cross-env": "^7.0.2",
        "express": "^4.17.1",
        "helmet": "^3.23.3",
        "react": "^16.13.1",
        "react-dom": "^16.13.1",
        "react-router": "^5.2.0",
        "react-router-dom": "^5.2.0",
        "react-scripts": "3.4.1"
    },
    "proxy": "http://localhost:5000",
    "scripts": {
        "build": "node ./buildScript",
        "start-server": "cross-env NODE_ENV=development nodemon server/app.js",
        "start-front": "PORT=8080 react-scripts start",
        "build-front": "react-scripts build",
        "test": "react-scripts test",
        "eject": "react-scripts eject",
        "start": "concurrently \"npm run start-server\" \"npm run start-front\" --kill-others"
    },
    "eslintConfig": {
        "extends": "react-app"
    },
    "browserslist": {
        "production": [
            ">0.2%",
            "not dead",
            "not op_mini all"
        ],
        "development": [
            "last 1 chrome version",
            "last 1 firefox version",
            "last 1 safari version"
        ]
    },
    "devDependencies": {
        "nodemon": "^2.0.4"
    }
}

后端包.json:

{
  "name": "server",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "mongoose": "^5.9.26"
  }
}

您能解释一下如何解决上述错误吗?

【问题讨论】:

  • 你使用的是灵活还是标准的应用引擎环境
  • 我的 app.yaml 只有对节点运行时的引用,所以我猜我猜是标准的

标签: node.js express google-app-engine gcloud


【解决方案1】:

没有理由在 AppEngine 上使用 nodemon。 AppEngine 将在您部署新文件时重新启动您的应用程序。在package.json 中使用node

"start-server": "cross-env NODE_ENV=development node server/app.js",

另外,我不会在启动脚本中指定环境变量,而是使用app.yaml 文件。 AppEngine 上不需要cross-env

env_variables:
  NODE_ENV: "development"

https://cloud.google.com/appengine/docs/standard/nodejs/config/appref#environment_variables

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-21
    • 1970-01-01
    • 1970-01-01
    • 2021-02-21
    • 1970-01-01
    • 2019-07-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多