Create-react-app: babel-preset-react-app breaks mocha because of `babel-preset-react-app` on ES6 imports

Created on 13 Nov 2017  路  1Comment  路  Source: facebook/create-react-app

First off I get the "this is opinionated" BS for this project. And I get the "you don't have to use it". Problem is a lot of people use it. And problem is, FB is forcing Jest down people's throat due to the fact that you're completely reliant on the magic in babel-preset-react-app. Opinionated should not extend so far as to prevent you from using your favorite testing framework and that's exactly what babel-preset-react-app is doing here.

Now before you tell me "we don't support mocha". That's also a BS line. This is a simple matter of an ES6 import error that babel should cover when running tests. That babel covered just fine when using es-2015 preset in other projects. So don't give me that nonsense. I can't even run mocha tests because babel-preset-react-app is doing something non-standard IMO. That's not a mocha problem, that's a magic problem...where it's not backwards compatible with basic babel.

I wrote this blog post a while back which allowed me to work with mocha. Don't ask me why I don't want Jest, I'm not going to get into that, it's a waste of time for me to explain that here. Just know that people will want to use Tape, Ava, Mocha, Jasmine, whatever. And this project is prohibiting what people were able to do in any react project, which is to simply add your test framework, and it worked seamlessly with babel presets. Now, you can't use babel-preset-es2015 because babel-preset-react-app1 overrides that. So guess what, it just broke this:

this was my work-around to allow me to use what I prefer, that is mocha. I added the following to my package.json and it was working fine:

  "babel": {
    "presets": [
      "react-app"
    ]
  }

But, after upgrading babel-preset-react-app which bumped it to 3.1.0, this no longer works. I now get the following after running mocha tests because somehow the create react app magic is doing something non-standard:

/src/test/isolated-unit/usecases/spec.template.js:1
(function (exports, require, module, __filename, __dirname) { import { React, expect, shallow, initStore } from '../../test.imports'; 

And of course FB will say not to add the 2015 preset because then you "aren't compatible with create-react-app". You aren't drinking magic so whatever you do won't work.

All I want to do is simply run mocha tests! this should be no problem and was not a problem in any other react project I've worked on that used babel. Well now it's an issue. What if I wanted to use Ava? Tape? Something else? so because people choose to pick create-react-app, we all have to change how we test and use Jest? That's complete BS.

My complaints in here won't go away till Facebook allows other testing frameworks into this otherwise overly opinionated framework. You're becoming a Microsoft and doing a disfavor for those who actually do write tests. We don't want Jest all time, some of us prefer other frameworks. This is ridiculous. If I have a client which wants to use create-react-app I should be able to say "fine" but be able to at least put my own damn testing framework in that works for the team or myself.

question

Most helpful comment

Our Babel preset no longer includes CommonJS transform (since it鈥檚 unnecessary if ES6 modules are supported out of the box, as they are by Webpack). You can include it yourself with something like:

 "babel": {
    "presets": [
      "react-app"
    ],
    "plugins": [
      "transform-es2015-modules-commonjs"
    ]
  }

I think this should work, but let me know if not.

"this is opinionated" BS
FB is forcing Jest
That's complete BS.
My complaints in here won't go away
This is ridiculous.

Please stop.

I鈥檝e assumed good intent in our past conversations and tried to be empathetic towards your requests. However, this is clearly not working. Please consider this a warning.

Nobody is forcing you to use this project鈥攊n fact we actively encourage forking for people who aren鈥檛 happy with the default configuration. We have many friendly forks for features like TypeScript support, CSS modules, decorators, etc. You are welcome to maintain your own. None of their authors have been so dismissive of the work we鈥檙e doing as you have been. Perhaps you could also try to be a little more positive?

I鈥檒l put it bluntly: you will get blocked from creating more issues in this repository if you鈥檙e unable to participate in a conversation without passive-aggressive attacks and finger pointing. There is limited amount of effort we can spend on the issues, and I would much rather spend it on people who can respectfully engage in a conversation, especially when there is a difference in opinions.

>All comments

Our Babel preset no longer includes CommonJS transform (since it鈥檚 unnecessary if ES6 modules are supported out of the box, as they are by Webpack). You can include it yourself with something like:

 "babel": {
    "presets": [
      "react-app"
    ],
    "plugins": [
      "transform-es2015-modules-commonjs"
    ]
  }

I think this should work, but let me know if not.

"this is opinionated" BS
FB is forcing Jest
That's complete BS.
My complaints in here won't go away
This is ridiculous.

Please stop.

I鈥檝e assumed good intent in our past conversations and tried to be empathetic towards your requests. However, this is clearly not working. Please consider this a warning.

Nobody is forcing you to use this project鈥攊n fact we actively encourage forking for people who aren鈥檛 happy with the default configuration. We have many friendly forks for features like TypeScript support, CSS modules, decorators, etc. You are welcome to maintain your own. None of their authors have been so dismissive of the work we鈥檙e doing as you have been. Perhaps you could also try to be a little more positive?

I鈥檒l put it bluntly: you will get blocked from creating more issues in this repository if you鈥檙e unable to participate in a conversation without passive-aggressive attacks and finger pointing. There is limited amount of effort we can spend on the issues, and I would much rather spend it on people who can respectfully engage in a conversation, especially when there is a difference in opinions.

Was this page helpful?
0 / 5 - 0 ratings