未知选项:… / .babelrc.presets

我正在使用Babel 6 for es2015,并且需要使用babel-preset-es2015babel-preset-react

我在.babelrc添加了presets属性,但是它给我一个错误:

 ERROR in ./src/client/entry.js Module build failed: ReferenceError: [BABEL] /Users/brick/Dropbox/learncoding/node.js/isomorphic/src/client/entry.js: Unknown option: /Users/brick/Dropbox/learncoding/node.js/isomorphic/.babelrc.presets at Logger.error (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-core/lib/transformation/file/logger.js:58:11) at OptionManager.mergeOptions (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-core/lib/transformation/file/options/option-manager.js:126:29) at OptionManager.addConfig (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-core/lib/transformation/file/options/option-manager.js:107:10) at OptionManager.findConfigs (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-core/lib/transformation/file/options/option-manager.js:168:35) at OptionManager.init (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-core/lib/transformation/file/options/option-manager.js:229:12) at File.initOptions (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-core/lib/transformation/file/index.js:147:75) at new File (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-core/lib/transformation/file/index.js:137:22) at Pipeline.transform (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-core/lib/transformation/pipeline.js:164:16) at transpile (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-loader/index.js:12:22) at Object.module.exports (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-loader/index.js:69:12) @ multi main 

我的.babelrc文件是:

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

我可以运行babel src -d lib命令,它工作。 但是,如果我运行npm start通过package.json运行babel ,则会显示错误。

我想我可以忽略错误,因为应用程序运行。 但我想知道为什么这个错误,并不确定它会影响。

我在package.json中的scripts是:

 "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "clean": "rm -rf lib", "build": "npm run clean && /usr/local/bin/babel src -d lib --experimental", "server": "nodemon lib/server/server", "dev-server": "node lib/server/webpack", "watch-js": "/usr/local/bin/babel src -d lib --experimental -w", "start": "npm run watch-js & npm run dev-server & npm run server" }, 

我的entry.js

 import React from "react"; import Router from "react-router"; import ReactDOM from "react-dom"; import routes from "./routes"; import DataWrapper from './DataWrapper'; import createBrowserHistory from 'history/lib/createBrowserHistory'; let history = createBrowserHistory(); var data = JSON.parse(document.querySelector('#data').innerHTML); ReactDOM.render(<DataWrapper data={data}><Router history = {history}>{routes}</Router></DataWrapper>, document.querySelector('#app')); 

       

网上收集的解决方案 "未知选项:… / .babelrc.presets"

我发现这个问题是由babel-loaderbabel-core

package.json ,依赖关系被声明为^5.3.3所以它不会更新到6.x. 将其更改为>=5.3.3^6.0.0

^意味着升级子版本,但不升级主版本。

确保在node_modules有实际的预设库。

我有类似的,但稍有不同的错误信息。 原因是我试图使用react预设为babel,但babel-react-preset从我的node_modules丢失。最终的结果是, node_modules试图使用react库的内容作为预设。

 ERROR in ./ui/js/myproject.js Module build failed: ReferenceError: [BABEL] /home/jsyrjala/myproject/ui/js/myproject.js: Unknown option: /home/jsyrjala/myproject/node_modules/react/react.js.Children at Logger.error (/home/jsyrjala/myproject/node_modules/babel-core/lib/transformation/file/logger.js:43:11) at OptionManager.mergeOptions (/home/jsyrjala/myproject/node_modules/babel-core/lib/transformation/file/options/option-manager.js:270:18) at OptionManager.mergePresets (/home/jsyrjala/myproject/node_modules/babel-core/lib/transformation/file/options/option-manager.js:333:16) at OptionManager.mergeOptions (/home/jsyrjala/myproject/node_modules/babel 

我可以使用babel src --out-dir lib ,但不能使用npm run XXX 。 我在我的机器上全局安装了Babel-cli@6.18.0 CLI,在安装了babel-cli @ local项目之后,它可以和npm run

我试图构buildpreact时候遇到了这个错误。 原来,我在父目录中有一个.babelrc文件,这是干扰; 消除后,问题就消失了。

在我的一些情况下,我有全球安装的babel引发相同的错误。 您可以先卸载babel,然后安装babel-cli ^ 6.26.0作为您的依赖项的一部分,然后尝试运行命令npm start again