I have multiple projects in react in a monorepo: app1
app2
app3
, and each app is built with webpack and babel.
I want to create a shared directory with shared components between the apps, so I created in the monorepo another directory shared
.
( I executed in each project npm i ../shared
)
But when I import componets from shared
inside one the of the apps, babel throws an exception: Add @babel/preset-react (https://git.io/JfeDR) to the 'presets' section of your Babel config to enable transformation. If you want to leave it as-is, add @babel/plugin-syntax-jsx (https://git.io/vb4yA) to the 'plugins' section to enable parsing.
NOTE: if I import simple functions from shared
it works, only when importing components it does not work.
What configuration can I add so I can create a shared directory with shared components?
The .babelrc
file I have in each app looks like this
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"browsers": ["chrome >= 50"]
},
"useBuiltIns": "usage",
"corejs": 3
}
],
"@babel/preset-react",
"@babel/preset-typescript"
],
"plugins": ["@babel/plugin-syntax-jsx", "@babel/plugin-transform-react-jsx", "@babel/plugin-transform-runtime"]
}