【问题标题】:Babel and Deploy Nodejs to Google App EngineBabel 并将 Nodejs 部署到 Google App Engine
【发布时间】:2017-07-27 21:57:02
【问题描述】:

我是一个新手 nodejs。我在将 nodejs 应用程序部署到谷歌应用程序引擎时遇到了麻烦。这是我的错误,我一直在尝试修复它,但它不起作用。我已经安装了 babel。

错误

更新服务 [默认]...失败。
错误:(gcloud.app.deploy)错误响应:[9] 应用启动错误:

restaurant_api@1.0.0 预启动 /app npm 运行 -s 构建

你错误地安装了 babel 包,它在 Babel 6 中是无操作的。 Babel 的 CLI 命令已从 babel 包移至 babel-cli 包。

npm 卸载 babel

npm install --save-dev babel-cli

这是我的 package.json

 "main": "dist",
 "scripts": {
    "dev": "NODE_ENV=development nodemon -w src --exec \"babel-node src --presets es2015,stage-0\"",
    "build": "babel src -s -D -d dist --presets es2015,stage-0",
    "start": "NODE_ENV=production pm2 start dist",
    "prestart": "npm run -s build",
    "lint": "eslint src",
    "test": "echo \"Error: no test specified\" && exit 1",
    "babel-version": "babel --version"
  },
  "eslintConfig": {
    "parserOptions": {
      "ecmaVersion": 7,
      "sourceType": "module"
    },
    "env": {
      "node": true
    },
    "rules": {
      "no-console": 0,
      "no-unused-vars": 1
    }
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "babel": "^6.23.0",
    "body-parser": "^1.17.0",
    "express": "^4.15.0",
    "express-jwt": "^5.1.0",
    "jsonwebtoken": "^7.3.0",
    "mongoose": "^4.8.5",
    "passport": "^0.3.2",
    "passport-local": "^1.0.0",
    "passport-local-mongoose": "^4.0.0",
    "pm2": "^2.4.2"
  },
  "devDependencies": {
    "babel-cli": "^6.23.0",
    "babel-eslint": "^7.1.1",
    "babel-preset-es2015": "^6.22.0",
    "babel-preset-stage-0": "^6.22.0",
    "eslint": "^3.16.1"
  }

【问题讨论】:

  • 答案在错误信息中——运行npm uninstall babel,然后是npm install --save-dev babel-cli

标签: node.js google-app-engine deployment ecmascript-6 babeljs


【解决方案1】:

问题很简单,如果你看清楚GAE,没有安装dev-dependencies。所以把你的 dev-deps 移到 deps 里面,就像我做的那样,babel no found error 就消失了。

    {
  "name": "scraping",
  "version": "0.3.0",
  "description": "Starter project for an ES6 RESTful Express API",
  "main": "dist",
  "scripts": {
    "dev": "nodemon -w src --exec \"babel-node src --presets es2015,stage-0\"",
    "build": "babel src -s -D -d dist --presets es2015,stage-0",
    "start": "node dist",
    "prestart": "npm run -s build",
    "test": "eslint src"
  },
  "eslintConfig": {
    "extends": "eslint:recommended",
    "parserOptions": {
      "ecmaVersion": 7,
      "sourceType": "module"
    },
    "env": {
      "node": true
    },
    "rules": {
      "no-console": 0,
      "no-unused-vars": 1
    }
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/developit/express-es6-rest-api.git"
  },
  "author": "Saransh  Sharma <jason@developit.ca>",
  "license": "MIT",
  "dependencies": {
    "body-parser": "^1.13.3",
    "compression": "^1.5.2",
    "cors": "^2.7.1",
    "express": "^4.13.3",
    "morgan": "^1.8.0",
    "resource-router-middleware": "^0.6.0",
    "@jonstuebe/scraper": "^0.1.4",
    "babel-cli": "^6.9.0",
    "babel-core": "^6.9.0",
    "babel-preset-es2015": "^6.9.0",
    "babel-preset-stage-0": "^6.5.0",
    "eslint": "^3.1.1",
    "nodemon": "^1.9.2"
  },
  "devDependencies": {
    "babel-cli": "^6.9.0",
    "babel-core": "^6.9.0",
    "babel-preset-es2015": "^6.9.0",
    "babel-preset-stage-0": "^6.5.0",
    "eslint": "^3.1.1",
    "nodemon": "^1.9.2"
  },
  "bugs": {
    "url": "https://github.com/developit/express-es6-rest-api/issues"
  },
  "homepage": "https://github.com/developit/express-es6-rest-api#readme",
  "keywords": [
    "scraper",
    "product",
    "from",
    "amazon"
  ]
}

【讨论】:

    【解决方案2】:

    您需要全局安装 babel-cli,即运行命令“npm install babel-cli -g”作为构建 npm 脚本的一部分,或者创建一个预安装脚本来安装它,如果您想保留它更多组织起来以防您以后需要添加更多内容。

    "scripts": {
    "dev": "NODE_ENV=development nodemon -w src --exec \"babel-node src --presets es2015,stage-0\"",
    "build": "npm install bable-cli -g && babel src -s -D -d dist --presets es2015,stage-0",
    

    【讨论】:

      【解决方案3】:

      线索在错误信息中。

      在你的 devDependencies 部分,你已经包含了 babel-cli。 但是,您的依赖项部分仍然引用了"babel": "^6.23.0"

      要么删除这一行,要么用 babel-cli 替换它,留下:

      "dependencies": {
        "babel-cli": "^6.23.0",
        "body-parser": "^1.17.0",
        "express": "^4.15.0",
        "express-jwt": "^5.1.0",
        "jsonwebtoken": "^7.3.0",
        "mongoose": "^4.8.5",
        "passport": "^0.3.2",
        "passport-local": "^1.0.0",
        "passport-local-mongoose": "^4.0.0",
        "pm2": "^2.4.2"
      },
      

      【讨论】:

      • 抱歉我的转储问题,我已经按照说明修复了 npm uninstall babel / npm install --save-dev babel-cli,但是当我部署到谷歌应用引擎:sh:1:babel:未找到
      猜你喜欢
      • 1970-01-01
      • 2015-02-19
      • 2017-09-29
      • 1970-01-01
      • 1970-01-01
      • 2020-11-24
      • 2016-09-20
      • 2020-05-06
      • 2017-09-04
      相关资源
      最近更新 更多