简体   繁体   English

需要帮助了解如何将 MERN 应用部署到 gcloud 应用引擎

[英]Need help understanding how to deploy a MERN app to gcloud app engine

I am trying to deploy a MERN app to gcloud app engine instance.我正在尝试将 MERN 应用程序部署到 gcloud 应用程序引擎实例。

When I deploy it and look at the logs, it's complaining about nodemon in the start server script .当我部署它并查看日志时,它在 start server script 抱怨 nodemon I Thought the app was suppose t run off the build and that those scripts were for development.我认为该应用程序假设不会在构建过程中运行,并且这些脚本是用于开发的。

Here is the error:这是错误:

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

Front end package.json:前端package.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"
    }
}

Back end package.json:后端 package.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"
  }
}

Can you explain how to address the error above?你能解释一下如何解决上面的错误吗?

There's no reason to use nodemon on AppEngine.没有理由在 AppEngine 上使用nodemon AppEngine will restart your app when you deploy new files.当您部署新文件时,AppEngine 将重新启动您的应用程序。 Juse use node in package.json :package.json中使用node

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

Also, rather than specifying the environment variable in the start script, I'd use the app.yaml file.此外,我不会在启动脚本中指定环境变量,而是使用app.yaml文件。 You don't need cross-env on AppEngine:您不需要 AppEngine 上cross-env环境:

env_variables:
  NODE_ENV: "development"

See https://cloud.google.com/appengine/docs/standard/nodejs/config/appref#environment_variables请参阅https://cloud.google.com/appengine/docs/standard/nodejs/config/appref#environment_variables

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM