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.

addBabelPlugins is not working

See original GitHub issue

In CRA3, I get an error of typescript namespace which is

Non-declarative namespaces are only supported experimentally in Babel.

look like I need @babel/plugin-transform-typescript to resolve it, but I add it uses addBabelPlugins still get this error.

module.exports = config => {
  const {
    entry,
    resolve = {},
    module: {rules},
  } = config;
  const {alias = {}} = resolve;
  // find index of eslint rule
  const findRuleIndex = cb => rules.findIndex(rule => cb(rule));
  const eslintRuleIndex = findRuleIndex(
    ({use}) => use && /eslint/.test(use[0].loader),
  );

  config.module.rules.splice(eslintRuleIndex, 1);
  config.entry.pop();
  config.entry = [...entry, Path.resolve('./src/app/index.tsx')];

  return override(
    addWebpackAlias({
      ...alias,
      '~': Path.resolve('src/app'),
      '~imgs': Path.resolve('src/app/assets/static'),
    }),
    ...addBabelPlugins([
      '@babel/plugin-transform-typescript',
      {allowNamespaces: true},
    ]),
  )(config);
};

This is my override config file.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
zxf4399commented, May 29, 2020

@m93a now it work!

1reaction
m93acommented, Apr 21, 2020

This is weird… I use a minimal config with:

const {
    override,
    addExternalBabelPlugin
  } = require("customize-cra");

module.exports = override(
    addBabelPlugin([
        "@babel/plugin-transform-typescript",
        { allowNamespaces: true }
    ])
);

but Babel acts as if the option allowNamespaces wasn’t there…

@youncccat Did you figure it out?

Read more comments on GitHub >

github_iconTop Results From Across the Web

React-App- Rewired won't add Babel Plugin - Stack Overflow
I am using a config-overrides.js file that looks like this: const { override, addBabelPlugins, addDecoratorsLegacy, fixBabelImports } = require( ...
Read more >
How to use the customize-cra.addBabelPlugin function ... - Snyk
Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues...
Read more >
Customize-cra-my NPM - npm.io
A simple helper that calls addBabelPlugin for each plugin you pass in here. Make sure you use the spread operator when using this,...
Read more >
@zhigang1992/customize-cra - npm
addBabelPlugins (plugins). A simple helper that calls addBabelPlugin for each plugin you pass in here. Make sure you use the spread operator when ......
Read more >
Modify Create React App's Babel Configuration Without Ejecting
We're not calling react-app-rewired directly, but it's a required ... In our case, addBabelPlugins is what we need to add both plugins.
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