I try to create a monorepo with 2 React packages:
- TypeScript (npx create-react-app
app
--template typescript) - JavaScript (
ui
)
I've got a basic lerna.json
configuration
{
"packages": ["packages/*"],
"version": "1.0.0"
}
In the ui
package I simply export one Button (from src/Button.jsx
):
import React from 'react';
const Button = () => {
return (
<button>
Start
</button>
)
}
export default Button;
I've bootstrapped app
to use the ui
package.
Importing it inside the app
causes the following error:
Failed to compile
/lerna-demo/packages/ui/src/Button.jsx 5:4
Module parse failed: Unexpected token (5:4)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| const Button = () => {
| return (
> <button>
| Start
| </button>
Is there a way to add a loader to lerna or app
to fix the import?
EDIT
The project structure:
lerna-demo/
- node_modules/
- lerna.json
- package.json
- packages/
- app (created using create-react-app)
- ...
- ui
- node_modules/
- package.json
- yarn.lock
- src/
- Button.jsx
The way I import the Button component:
import React from 'react';
import logo from './logo.svg';
import './App.css';
import * as Button from 'ui/src/Button';
const App: React.FC = () => {
return (
<div className="App">
<Button />
</div>
);
}
export default App;