Babel Preset ENV问题

时间:2017-11-14 10:23:45

标签: node.js babel

美好的一天:

我刚刚通过NPM安装了Babel Preset-ENV并遇到了这个问题:

{
  "name": "api",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "nodemon -L server.js --ignore 'db/schema.json' --exec babel-node server.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@babel/core": "^7.0.0-beta.32",
    "@babel/preset-env": "^7.0.0-beta.32",
    "babel-core": "^6.26.0",
    "express": "^4.16.2",
    "express-graphql": "^0.6.11",
    "express-oauth-server": "^2.0.0",
    "graphql": "^0.11.7",
    "jsonwebtoken": "^8.1.0",
    "mongo": "^0.1.0",
    "mongoose": "^4.13.2",
    "password-hash": "^1.2.2",
    "react-relay": "^1.4.1"
  },
  "devDependencies": {
    "babel-cli": "^6.26.0"
  }
}

我的Package.JSON如下:

vagrant@vagrant-ubuntu-trusty-64:~/api$ cat .babelrc 
{
  "presets": [
    ["@babel/preset-env", {
      "targets": {
        "node": "current"
      }
    }]
  ]
}

我的 .babelrc 也是这样:

stage-0

在升级之前,我使用的是es20154.6.1预设,但是在升级之后,这已经是错误的。请注意,我的NPM版本为.gallery { display: -ms-flexbox; display: flex; justify-content: space-between; -webkit-justify-content: space-around; -ms-flex-pack: justify; margin: 0 auto; border: 2px solid blue; }

感谢。

2 个答案:

答案 0 :(得分:0)

我按照此说明进行了设置https://github.com/babel/babel/tree/master/experimental/babel-preset-env但是,此处的文档似乎已过时。我被建议使用此处提到的官方babel文档进行预设设置https://babeljs.io/

答案 1 :(得分:0)

确保您的Babel依赖项彼此兼容。

这样:

"@babel/core": "^7.0.0-beta.32",
"@babel/preset-env": "^7.0.0-beta.32",
"babel-core": "^6.26.0",
"babel-cli": "^6.26.0"

应该是这样的:

"@babel/cli": "^7.0.0-beta.34",
"@babel/core": "^7.0.0-beta.34",
"@babel/node": "^7.0.0-beta.34",