Babel Error:未知选项:babelrc.presets

时间:2016-04-25 19:56:14

标签: npm webpack babeljs

使用Jest运行测试时,我需要我的.babelrc文件才能运行。 运行npm start时,它只能在没有.babelrc文件的情况下运行,错误:

{
  "name": "reactjs",
  "version": "1.0.0",
  "description": "",
  "main": "src/app.js",
  "author": "x",
  "license": "ISC",
  "scripts": {
    "start": "webpack-dev-server --port 3000",
    "test": "jest"
  },
  "jest": {
    "scriptPreprocessor": "<rootDir>/node_modules/babel-jest",
    "unmockedModulePathPatterns": [
      "react",
      "react-dom",
      "react-addons-test-utils",
      "fbjs"
    ]
  },
  "devDependencies": {
    "babel-core": "^6.7.*",
    "babel-jest": "^11.0.2",
    "babel-loader": "^5.0.0",
    "babel-preset-es2015": "^6.6.0",
    "babel-preset-react": "^6.5.0",
    "jest-cli": "^11.0.2",
    "react-addons-test-utils": "^0.14.8",
    "webpack": "^1.12.*",
    "webpack-dev-server": "^1.10.*"
  },
  "dependencies": {
    "react": "^0.13.3"
  }
}

我猜测它与我拥有的babel版本有关,但我试图关注&#34;回答&#34;对于这个问题:The String type in Scala has methods that come either from the underlying Java String (see the documentation corresponding to your Java version, for example http://docs.oracle.com/javase/8/docs/api/java/lang/String.html) or are added implicitly through scala.collection.immutable.StringOps. 但无济于事。

这是我的package.json:

{
  "presets": [
     "react",
     "es2015"
  ]
}

和我的.babelrc:

module.exports = {
    entry: [
        './src/app.js'
    ],
    output: {
        path: __dirname,
        filename: "bundle.js"
    },
    module: {
        loaders: [{
            test: /\.jsx?$/,
            loader: 'babel',
            exclude: /node_modules/
        }]
    }
};

和我的webpack配置,如果它相关:

{{1}}

2 个答案:

答案 0 :(得分:2)

您已列出babel-core@^6但正在使用babel-loader@5,请将babel-loader更新为最新版本。

答案 1 :(得分:0)

我可以使用babel src --out-dir lib,但不能使用npm run XXX使用babel-core@6.20.0和babel-loader@6.2.9。我全球安装Babel-cli@6.18.0 CLI在我的机器上,安装babel-cli @ local项目后,它可以与npm run一起使用。