react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Failed to start project if .babelrc is added

Open am5a03 opened this issue 10 years ago • 3 comments

I've added a .babelrc in my project's root directory

{
  "whitelist": [
    "es7.classProperties",
    "es7.decorators"
  ]
}

It cannot be started, I got the same error message as in https://github.com/facebook/react-native/issues/4690

C:\Users\Raymond\workspace\ReactNativeProjs\JGolden\node_modules\babel-core\lib\transformation\file\logger.js:41
    throw new Constructor(this._buildMessage(msg));
    ^

ReferenceError: [BABEL] C:\Users\Raymond\workspace\ReactNativeProjs\JGolden\node_modules\react-native\local-cli\bundle\bundle.js: Unknown option: base.whitelist
    at Logger.error (C:\Users\Raymond\workspace\ReactNativeProjs\JGolden\node_modules\babel-core\lib\transformation\file\logger.js:41:11)
    at OptionManager.mergeOptions (C:\Users\Raymond\workspace\ReactNativeProjs\JGolden\node_modules\babel-core\lib\transformation\file\options\option-manager.js:262:18)
    at OptionManager.init (C:\Users\Raymond\workspace\ReactNativeProjs\JGolden\node_modules\babel-core\lib\transformation\file\options\option-manager.js:416:10)
    at File.initOptions (C:\Users\Raymond\workspace\ReactNativeProjs\JGolden\node_modules\babel-core\lib\transformation\file\index.js:191:75)
    at new File (C:\Users\Raymond\workspace\ReactNativeProjs\JGolden\node_modules\babel-core\lib\transformation\file\index.js:122:22)
    at Pipeline.transform (C:\Users\Raymond\workspace\ReactNativeProjs\JGolden\node_modules\babel-core\lib\transformation\pipeline.js:42:16)
    at Object.transformFileSync (C:\Users\Raymond\workspace\ReactNativeProjs\JGolden\node_modules\babel-core\lib\api\node.js:116:10)
    at compile (C:\Users\Raymond\workspace\ReactNativeProjs\JGolden\node_modules\babel-register\lib\node.js:102:20)
    at loader (C:\Users\Raymond\workspace\ReactNativeProjs\JGolden\node_modules\babel-register\lib\node.js:130:14)
    at Object.require.extensions.(anonymous function) [as .js] (C:\Users\Raymond\workspace\ReactNativeProjs\JGolden\node_modules\babel-register\lib\node.js:140:7)

However, this .babelrc works in one of my previous projects, which is using react-native 0.14.2 Here is an excerpt of the dependency of this new project:

PS C:\Users\Raymond\workspace\ReactNativeProjs\JGolden> npm ls
[email protected] C:\Users\Raymond\workspace\ReactNativeProjs\JGolden
└─┬ [email protected]
  ├── [email protected]
  ├── [email protected]
  ├─┬ [email protected]
  │ ├─┬ [email protected]

And the dependency of my old project

├─┬ [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]

Both are using exactly the same .babelrc, but the new project simply doesn't start. I tried to copy node_modules to my new project, and it starts.

am5a03 avatar Dec 20 '15 06:12 am5a03

Hey am5a03, thanks for reporting this issue!

React Native, as you've probably heard, is getting really popular and truth is we're getting a bit overwhelmed by the activity surrounding it. There are just too many issues for us to manage properly.

  • If you don't know how to do something or not sure whether some behavior is expected or a bug, please ask on StackOverflow with the tag react-native or for more real time interactions, ask on Discord in the #react-native channel.
  • If this is a feature request or a bug that you would like to be fixed, please report it on Product Pains. It has a ranking feature that lets us focus on the most important issues the community is experiencing.
  • We welcome clear issues and PRs that are ready for in-depth discussion. Please provide screenshots where appropriate and always mention the version of React Native you're using. Thank you for your contributions!

facebook-github-bot avatar Dec 20 '15 06:12 facebook-github-bot

@am5a03 since v0.16.0 React Native uses BABEL6, which currently does not support decorators, so they will not work. From the Release notes: JS decorators won't work until T2645 lands in Babel. It's being worked on. The proposal for decorators is not final and therefore Babel 6 left decorator support out for now.

And since then also .barbelrc are not supported anymore. You have to remove them from any other node_module too. Please have a look at this related issue https://github.com/facebook/react-native/issues/4062

ms88privat avatar Dec 20 '15 10:12 ms88privat

Closing for #4062

christopherdro avatar Dec 21 '15 00:12 christopherdro