I have a fairly complex setup regarding two React apps.
Context:
I was tasked to create a design system using ReactJS to be later on used in their main app.
So i did made a design system in 1 week (w/ small knowledge in ReactJS; mainly a Vue dev) made with NextJS + TailwindCSS 3 + TypeScript
in their latest versions.
Now i got their main React app downloaded locally; not Typescript, and all packages were outdated already using node 6 and react 16.13. So i updated them to node 16 and React 17 along with other packages.
Also main app doesn't use functional components while mine does.
Problem:
Now the problem is how do i connect the two apps? The main app (non TS) and my design system (TS with NextJS) so i could use my design system components on their app?
What i've tried to do so far:
I used npm-link
to link my design system npm to the main app. The link was successful however main app cannot find my tsx
files.
Also tried building my design system app by next build
.
I tried two things on importing:
Importing a TSX component
I tried importing by import SearchBar from "design-system/components/SearchBar";
and was met with error Module not found: Error: Can't resolve
.
Importing a JSX component
Tried importing a Test
jsx component from my design system and met with error:
Module parse failed: Unexpected token (4:9)
File was processed with these loaders:
* ./node_modules/@pmmmwh/react-refresh-webpack-plugin/loader/index.js
You may need an additional loader to handle the result of these loaders.
|
| export default function Test() {
> return <div>TEST COMPONENT FROM JS</div>;
| }
|
Notes
Also take note that design system uses functional components while main app doesn't.
I was under impression that i could use any framework in design system regardless of what React or does app have TS or not, since it will be a npm package even if it's not published yet, and thought can import it and use it anywhere as long as it is React.
main app was created with
react-scripts
; design system was created withcreate next-app --typescript
Here's my ts.config.json
from the design system app
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"baseUrl": "."
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "."],
"exclude": ["node_modules"],
"moduleResolution": ["node_modules", ".next", "node"]
}
What steps should i make?
- Should i adjust my design system to use Class-based components and use JSX instead of TS?
- Is there anything i can do on the main app to be able to import JSX or preferably TSX files from another react node app?
- Should i make a new
create-react-app
or just start from scratch without NextJS for design system? NextJS wasn't really needed in my components.