I am using Babel 6 for es2015 and react which requires babel-preset-es2015
and babel-preset-react
.
I add the presets
property in .babelrc
but it throw me an error:
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
My .babelrc
file is:
{
"presets": [
"es2015",
"react"
]
}
I can run babel src -d lib
command, it works. But if I run npm start
to run the babel
via package.json
, the error appears.
I think I can ignore the error because the app runs. But I want to know why this error and not sure what it affects.
My scripts
in package.json
is:
"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"
},
My entry.js
is
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'));
In some cases like mine, I have babel installed globally which throws the same error. You can uninstall the babel first then install babel-cli ^6.26.0 as part of your dependencies then try running the command npm start again
I can work with
babel src --out-dir lib
, but not withnpm run XXX
. I install Babel-cli@6.18.0 CLI globally on my machine, after I install babel-cli@ locally project, it can works withnpm run
.I figured out this problem is caused by the version of
babel-loader
andbabel-core
.In the
package.json
the dependencies was stated^5.3.3
so it won't update to 6.x. Change it to>=5.3.3
or^6.0.0
.^
means upgrade the sub version but don't upgrade main version.Make sure that you have those preset libraries actually in your
node_modules
.I had similar but slightly different error message. The reason was that I was trying to use
react
preset for babel butbabel-react-preset
was missing from mynode_modules
.The end result was that babel was trying to use contents ofreact
library as a preset.I ran into this error when trying to build
preact
. Turns out I had a.babelrc
file in the parent directory that was interfering; after removing it the problem went away.