【问题标题】:Monorepo with paths from Typescript is not working带有来自 Typescript 的路径的 Monorepo 不起作用
【发布时间】:2019-10-25 08:18:55
【问题描述】:

我有具有以下文件结构的 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)

我想在server/getData.ts中使用来自shared/sanitizeData.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";

你能帮帮我吗?

【问题讨论】:

    标签: javascript typescript tsconfig monorepo yarn-workspaces


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2016-06-06
      • 2020-04-20
      • 2020-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-15
      • 2013-07-06
      • 1970-01-01
      相关资源
      最近更新 更多