Babel预设环境问题

3

您好:

我刚刚通过NPM安装了Babel Preset-ENV,出现了以下问题:

[nodemon] starting `babel-node server.js server.js`
/home/vagrant/api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:328
        throw e;
        ^

TypeError: Cannot read property 'loose' of undefined (While processing preset: "/home/vagrant/api/node_modules/@babel/preset-env/lib/index.js")
    at _default (/home/vagrant/api/node_modules/@babel/plugin-transform-modules-commonjs/lib/index.js:19:22)
    at Function.memoisePluginContainer (/home/vagrant/api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:113:13)
    at Function.normalisePlugin (/home/vagrant/api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:146:32)
    at /home/vagrant/api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30
    at Array.map (native)
    at Function.normalisePlugins (/home/vagrant/api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
    at OptionManager.mergeOptions (/home/vagrant/api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36)
    at /home/vagrant/api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:265:14
    at /home/vagrant/api/node_modules/babel-core/lib/transformation/file/options/option-manager.js:323:22
    at Array.map (native)

我的Package.JSON如下所示:

{
  "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"
  }
}

同时,我的 .babelrc 文件内容如下:

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

在升级之前,我使用的是 stage-0es2015 预设,并且它们是正常工作的。然而,在升级之后,这些预设出现了错误。请注意,我的 NPM 版本是 4.6.1
谢谢。
2个回答

1

请确保您的 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",

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接