question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

customize-cra + new JSX babel configuration not working

See original GitHub issue

Current behavior:

In docs of css-prop, I can setup babel configuration without inserting JSX pragma to every files. To do this, I installed customize-cra and override babel configuration using .babelrc and config-overrides.js. However, it isn’t working as expected and just showing error message like below.

You have tried to stringify object returned from css function. It isn’t supposed to be used directly (e.g. as value of the className prop), but rather handed to emotion so it can handle it (e.g. as value of css prop).

To reproduce:

https://codesandbox.io/s/customize-cra-emotion-snlzn

Expected behavior:

css prop should work as expected

Environment information:

You can see versions of packages in above reproduction.

THX

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
Andaristcommented, Jan 7, 2021

Your config-overrides.js should look like this:

const { override, useBabelRc, getBabelLoader } = require('customize-cra');

const removeBultinBabelConfig = config => {
  getBabelLoader(config).options.presets = [];
  getBabelLoader(config).options.plugins = [];
  return config;
}

module.exports = override(removeBultinBabelConfig, useBabelRc());

Please just re-add everything that you need to your babelrc because this removes builtin babel-preset-react-app.

0reactions
lacompartecommented, Mar 28, 2022

my ‘config-overrides.js’ file it’s perfect!

const { override, addWebpackAlias, addBabelPlugins, useBabelRc } = require('customize-cra');
const path = require('path');

const emotionPresetOptions = {
  sourceMap: true,
  autoLabel: 'dev-only',
  labelFormat: '[local]',
  cssPropOptimization: true,
};

const emotionbabelPreset = require('@emotion/babel-preset-css-prop').default(
  undefined,
  emotionPresetOptions,
);

module.exports = {
  webpack: override(
    useBabelRc(),
    ...addBabelPlugins(...emotionbabelPreset.plugins),
    addWebpackAlias({
      _: path.resolve(__dirname, 'src'),
    }),
  ),
};

Read more comments on GitHub >

github_iconTop Results From Across the Web

customize-cra - Support for the experimental syntax 'jsx' isn't ...
I am using react-app-rewired to configure my CRA project as I was having issues with 2 co-existing versions of React which I'm sure...
Read more >
Modify Create React App's Babel Configuration Without Ejecting
Learn how to modify the underlying Create React App configuration with customize-cra to include new babel plugins. All without having to ...
Read more >
Babel - Storybook
Storybook's webpack config by default sets up Babel for ES6 transpiling. It has three different modes: CRA - the mode for Create React...
Read more >
Create React App without Create React App - Bits and Pieces
This article talks about the process of creating react app without using any libraries or frameworks such as “create-react-app” , “NextJS” etc.
Read more >
Simplest Way to Install Babel Plugins in Create React App
Run npm start or yarn start to start the development server and see if everything works properly. Without Using .babelrc. In the above,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found