Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-App- Rewired won't add Babel Plugin

So I am trying to run react-native using react-native-web. It requires some babel plugins to be added.

My app was created using react-app-rewired. I have tried several ways to add the babel plugin, however, with no success.

I am using a config-overrides.js file that looks like this:

const { override, addBabelPlugins, addDecoratorsLegacy, fixBabelImports } = require('customize-cra');

const addHandleBarsLoader = config => {
    // add handlebars-loader so that handlebars templates in
    // webpack-dev-server's served html files are parsed
    // (specifically the meta tags)
    config.module.rules.push({ test: /\.html$/, loader: 'handlebars-loader' });
    return config;
}


module.exports = override(
    addHandleBarsLoader,
    fixBabelImports('import', {
        libraryName: 'antd',
        libraryDirectory: 'es',
        style: true,
      }),addBabelPlugins('@babel/plugin-proposal-class-properties'),
);

I know the other config override works, however the babel keeps ignoring the new plugin (which is installed, as well as everything else).

Also, I am building the app through the react-app-rewired build.

That is the error message I get while it tries to build

./node_modules/rn-bottom-drawer/src/BottomDrawer.js
SyntaxError: /Users/admin/Documents/Meirim/Workspace/meirim/node_modules/rn-bottom-drawer/src/BottomDrawer.js: Support for the experimental syntax 'classProperties' isn't currently enabled (13:20):

  11 |
  12 | export default class BottomDrawer extends Component{
> 13 |   static propTypes = {
     |                    ^
  14 |     /**
  15 |      * Height of the drawer.
  16 |      */

Add @babel/plugin-proposal-class-properties (https://git.io/vb4SL) to the 'plugins' section of your Babel configto enable transformation.

Many thanks(:

Gal

like image 906
Gal Gendler Avatar asked Jan 25 '20 19:01

Gal Gendler


People also ask

How to create react app using Babel plugin?

In create react app, you have to either use react-app-rewired or ejecting for custom babel configuration. But as another option, you can install it as a babel-plugins-macro. For pipeline operator, pipeline.macro can be used as I introduced.

How do I install create react app?

Begin by firing up your terminal and installing Create React App with the following command: The first step may take a while to complete depending on your internet connection. If you do not have npx installed, run npm install --global npx or yarn global add npx and then try the previous step again.

How do I add a Babel plugin to my project?

Install your Babel plugin (s). Suppose our Babel plugin is called babel-plugin-myPlugin: Open package.json located in the project root and edit the "scripts" field: Create .babelrc at the root of the project (where package.json is located) and add the following code.

Is it possible to eject a react app?

In this case, you may eject the app, but there are several reasons why you don’t want to do that. For this article, we’re going to add both the nullish coalescing operator and optional chaining syntax babel plugins. These plugins are both excluded from Create React App at the time of writing.


1 Answers

Found the solution, simply use a function called addExternalBabelPlugin instead

like image 99
Gal Gendler Avatar answered Oct 24 '22 01:10

Gal Gendler