我有具有以下文件结构的monorepo(纱线工作区):
├── 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)
我想使用shared/sanitizeData.ts
中的server/getData.ts
中的函数
我尝试使用Typescript中的paths
,根据文档来看,它看起来非常简单,但是我做错了事:
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";
能帮我吗?
答案 0 :(得分:3)
路径是相对于baseUrl
的,因此在您的情况下,您必须将["shared/*"]
替换为["../shared/*"]