11

我有具有以下文件结构的 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.tsin 中的函数server/getData.ts

我尝试paths从 Typescript 使用,根据文档它看起来很简单,但我做错了:

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";

请问你能帮帮我吗?

4

1 回答 1

5

路径相对于baseUrl,因此在您的情况下,您必须替换["shared/*"]["../shared/*"]

于 2020-01-16T11:06:26.613 回答