I'm working on a PHP
project using Typescript
and I'm trying to follow the same pattern for monorepo, similar to what NX
does. I'm having issues when trying to compile typescript
for each apps
.
This is my current structure:
.
├── apps/
│ ├── project-a/
│ ├── project-b/
│ └── project-c/
│ └── src/
│ ├── sass
│ └── ts/
│ ├── components/
│ └── index.ts
├── libs/
│ └── typescript/
│ ├── interface/
│ ├── abstract/
│ │ └── base.ts
│ └── components/
│ ├── header.ts
│ └── footer.ts
├── webpack/
│ └── dev.js
└── tsconfig.json
This is my tsconfig.json
{
"compilerOptions": {
"baseUrl": "./",
"esModuleInterop": true,
"module": "AMD",
"moduleResolution": "node",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"target": "ESNext",
"outDir": "dist",
"paths": {
"@libs/abstract": ["libs/typescript/abstract"],
"@libs/interface": ["libs/typescript/interface"],
"@libs/components": ["libs/typescript/components"],
}
}
}
And the error I'm getting is this:
Module not found: Error: Can't resolve '@libs/components' in '**\apps\project-c\src\ts';
Field 'browser' doesn't contain a valid alias configuration resolve as module.
**\apps\project-c\src\ts\node_modules doesn't exist or is not a directory
Basically I need to have basic functionality that is going to be used by all apps
from the libs
folder, but when I try to compile the project, I'm getting that error.
My webpack script is running with arguments to define and locate the app that needs to be compiled, for example:
yarn dev --theme=project-c
Which is going to build the path structure to the proper project. If I remove any imports from the libs
, it's compiling as expected, but as soon as I try to import, for example, the Header component, it fails.
I imagine it must be something with my tsconfig.json
settings, but none of the fixes I tried worked. Even tried to "copy" from an official NX monorepo settings, but still nothing.