Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unknown option: .../.babelrc.presets

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'));
like image 654
Brick Yang Avatar asked Nov 13 '15 03:11

Brick Yang


4 Answers

I figured out this problem is caused by the version of babel-loader and babel-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.

like image 52
Brick Yang Avatar answered Oct 29 '22 15:10

Brick Yang


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 but babel-react-preset was missing from my node_modules.The end result was that babel was trying to use contents of react library as a preset.

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
like image 27
Juha Syrjälä Avatar answered Oct 29 '22 13:10

Juha Syrjälä


I can work with babel src --out-dir lib, but not with npm run XXX. I install [email protected] CLI globally on my machine, after I install babel-cli@ locally project, it can works with npm run.

like image 2
echizen Avatar answered Oct 29 '22 13:10

echizen


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.

like image 2
Mispy Avatar answered Oct 29 '22 13:10

Mispy