So I am trying out monorepo design with lerna for our react applications.
the idea is to create one repo which will have all the react projects as lerna packages as well as some common modules/components which are shared across the applications.
now all these common modules/components are es6 modules. which are not transpiled. because there is continuous development going on the common modules as well. and if we build/transpile them I am sure react HMR will not work after that (a wild guess). following is my directory structure
package.json
lerna.json
|--packages
|--common
|--react-app
|--constants
|--utilities
common contains common react elements like table,accordion etc. which are exported as default es6 modules.
react-app imports common as dependency. react-app has webpack build configuration set.
now when i import common module into my react-app babel transform fails with this error
Button.component.jsx 7:19
Module parse failed: Unexpected token (7:19)
You may need an appropriate loader to handle this file type.
| const { Search } = Input;
| class TextBoxWithButton extends React.Component {
> static propTypes = {
| placeholder: PropTypes.string.isRequired,
| onAction: PropTypes.func.isRequired,
@ ./src/App/Modules/Todo/Components/Header/Header.component.jsx 10:0-111 16:25-41
@ ./src/App/Modules/Todo/Todo.component.jsx
@ ./src/App/Router/index.jsx
@ ./src/App/Layout/index.jsx
@ ./src/App/index.jsx
@ ./src/App.hot.js
@ ./src/index.jsx
which means babel-loader is unable to parse and transpile whats in the node_nodules folder which makes sense because all dependencies are expected to be already transpiled. but not always. if you manage local dependencies you cannot keep them build all the time (that's what i think)
now I have found some solutions online that enable 1bable-loader not to exclude node_modules or ignoring @mypackagein exclude regex. but nothing is working in my case.
here is what i have tried so far.
- remove
exlucde: /node_modules/frombabel-loader=> not working - use
require.resolve('babel-loader')=> not working - add
resolve.symlinks= false. - add
resolve.modules='node_modules'orpath.resove(__dirname,'node_modules')=> not working - add packages path to
babel-loaderincludeinclude: [srcPath, lernaPackagesPath],
nothing seem to work. is there something that i am missing ? here is the link to my git test repo.