【问题标题】:Getting the spread operater syntax error during the deployment to Heroku在部署到 Heroku 期间获取传播运算符语法错误
【发布时间】:2020-01-13 03:57:46
【问题描述】:

我在将应用部署到 Heroku 时遇到以下错误:

remote: SyntaxError: src/resolvers/Mutation.js: Unexpected token (21:16)
remote:   19 |         const user = await prisma.mutation.createUser({
remote:   20 |             data: {
remote: > 21 |                 ...data,
remote:      |                 ^
remote:   22 |                 password,
remote:   23 |                 permissions,
remote:   24 |                 authentication

在 Heroku 后期构建阶段,无法识别其余分布。

我目前在index.js 有以下内容:

import '@babel/polyfill'

我的package.json

  "dependencies": {
    "@babel/polyfill": "^7.0.0",
    "babel-cli": "^6.26.0",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "babel-preset-env": "^1.7.0",
    "babel-register": "^6.26.0",
    "bcryptjs": "^2.4.3",
    "cross-fetch": "^2.2.2",
    "env-cmd": "^8.0.2",
    "google-auth-library": "^4.2.3",
    "graphql": "^0.13.2",
    "graphql-cli": "^2.16.4",
    "graphql-yoga": "^1.14.10",
    "jsonwebtoken": "^8.3.0",
    "nodemailer": "^6.2.1",
    "prisma-binding": "^2.1.1",
    "stripe": "^7.1.0"
  },
  "devDependencies": {
    "babel-plugin-transform-es2015-destructuring": "^6.23.0",
    "jest": "^23.5.0",
    "nodemon": "^1.17.5"
  }

我试过_babelrc

{
    "presets": [
        "env"
    ],
    "plugins": [
        "transform-object-rest-spread"
    ]
}

{
    "presets": [
        "react",
        "es2015",
        "stage-3",
        "env"
    ],
    "plugins": [
        ["@babel/plugin-proposal-object-rest-spread", { "loose": true, "useBuiltIns": true }],
        "transform-es2015-destructuring"
    ]
}

{
  "presets": [
    "env",
    "stage-0",
    "react"
  ]
}

{
  "presets": ["react", "es2015"],
  "plugins": ["transform-es2015-destructuring", "transform-object-rest-spread"]
}

但无效。不知道如何解决这个问题。
....................

【问题讨论】:

  • _babelrc 是问题中的拼写错误,还是您使用的文件名确实如此?我不知道这是一个公认的 babel 配置文件——我只知道 .babelrc.babelrc.js 并且我认为它也可以在 package.json 中配置。
  • 可以显示package.json的脚本
  • @AlexanderNied 哇,你是对的。如果您想在回复中留下它,我会感谢您
  • 当然,谢谢,很高兴解决了您的问题:)
  • 看起来你正在混合不同版本的 Babel。使用所有 6.x 或 7.x。

标签: javascript node.js ecmascript-6 babeljs


【解决方案1】:

_babelrc 不是 babel 可识别的配置格式文件——要配置 babel,您需要使用其config files documentation 中列出的方法之一:

  • .babelrc
  • .babelrc.js
  • .babelrc.cjs
  • package.json

【讨论】:

    猜你喜欢
    • 2022-07-11
    • 2020-07-12
    • 2021-06-05
    • 2017-12-09
    • 1970-01-01
    • 2012-05-16
    • 2016-07-24
    • 2013-03-29
    • 2021-05-04
    相关资源
    最近更新 更多