Babel does not recognize `export Component from './Component'`

Viewed 168

I have installed @babel/plugin-proposal-export-default-from, but for some reason, my default export is not being transformed. Typescript keeps throwing the error,

Add @babel/plugin-proposal-export-default-from (https://git.io/vb4yH) to
    the 'plugins' section of your Babel config to enable transformation.

I've taken a look at this issue and have tried installing @babel/plugin-proposal-export-namespace-from as well, but to no avail.

What am I doing wrong here? Am I missing something?

My babel.config.json:

{
    "presets": [["@babel/preset-env", { "targets": { "node": "current" } }]],
    "plugins": ["@babel/plugin-proposal-export-default-from", "@babel/plugin-proposal-export-namespace-from"]
}

romantic-kirch-fzmvy

FWIW, I haven't ejected out of my CRA app, and I'm wondering if I need to do so, or use something like rewired, in order to use this in my project.

1 Answers

By default, create-react-app hides webpack, babel configurations and preconfigured. Which means if you build your project directly, the babel.config.json doesn't work. So you need to run npm run eject to customize the configuration. By the way, you may also need to upgrade react-scripts to 4.0.1 to do npm run eject. Once you done this, then your babel configuration works, and I think you shouldn't see the error your met. But I didn't try to find the reason of another error when I checked your demo.

Related