I have monorepo (yarn workpaces) with following file structure:
├── client (workspace @client)
│ ├── package.json
│ └── tsconfig.json (extended tsconfig)
├── server (workspace @server)
│ ├── getData.ts
│ ├── package.json
│ └── tsconfig.json (extended tsconfig)
├── shared
│ └── sanitizeData.ts
├── package.json (monorepo root)
└── tsconfig.json (base tsconfig)
And I want to use function from shared/sanitizeData.ts
in server/getData.ts
I tried to use paths
from Typescript, it looks pretty straightforward according to docs, but I'm doing something wrong:
error TS2307: Cannot find module '@shared/sanitizeData'.
server/tsconfig.json
:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"rootDir": "../",
"outDir": "build",
"paths": {
"@shared/*": ["shared/*"]
}
}
}
server/getData.js
:
import { sanitizeData } from "@shared/sanitizeData";
Could you help me please?
Paths are relative to baseUrl
, so in your case you'd have to replace ["shared/*"]
with ["../shared/*"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With