reactjs - Typescript build issue with lerna
问题描述
I currently have a lerna/react/TS project of the following structure:
.
├── lerna.json
├── package.json
├── packages
│ ├── patient
│ │ ├── package.json
│ │ ├── src
│ │ │ └── index.tsx
│ │ ├── tsconfig.build.json
│ │ └── tsconfig.json
│ └── appointment
│ ├── package.json
│ ├── src
│ │ └── index.tsx
│ ├── tsconfig.build.json
│ └── tsconfig.json
├── tsconfig.build.json
└── tsconfig.json
In packages/appointment/src/index.tsx
its importing the patient
module:
import { Patient } from '@ui-sdk/patient';
when running the build command tsc --project ./tsconfig.build.json
inside the appointment
folder, its adding the patient
code again.
Actual:
/packages/appointment/dist/patient/index.js
/packages/appointment/dist/appointment/index.js
Expected:
/packages/appointment/dist/index.js
The build config at the /packages/appointment/tsconfig.build.json
is as follows:
{
"extends": "../../tsconfig.build.json",
"compilerOptions": {
"outDir": "./dist",
"jsx": "react",
"esModuleInterop": true
},
"include": [
"src/**/*"
]
}
and the main tsconfig.json
at the root level:
{
"compilerOptions": {
"module": "esnext",
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"skipLibCheck": true,
"sourceMap": true,
"resolveJsonModule": true,
"moduleResolution": "node",
"declaration": true,
"baseUrl": ".",
"paths": {
"@ui-sdk/*": ["packages/*/src"]
},
},
"exclude": [
"node_modules",
"dist"
]
}
If I remove this section:
"baseUrl": ".",
"paths": {
"@ui-sdk/*": ["packages/*/src"]
},
The compilation throws an error
packages/appointment/src/index.tsx(2,24): error TS2307: Cannot find module '@ui-sdk/patient' or its corresponding type declarations.
Any idea how to make the build contain only the codes for that component only, instead of bringing the other files in the build folder?
解决方案
我刚刚遇到了同样的问题。问题是我不得不从tsconfig.build.json
文件中省略“路径”。
tsconfig.json
{
"extends" "./tsconfig.build.json",
"compilerOptions": {
"paths": {
"@ui-sdk/*": ["packages/*/src"]
}
}
}
tsconfig.build.json
{
"compilerOptions": {
// ...
}
}
这导致 TS 不会尝试解析您的本地包,而是将其视为对外部包的引用。
推荐阅读
- autodesk-forge - MarkupsCore Extension 自定义代码后无法与 Autodesk View 交互
- python - 在熊猫中按组检查5个不同年份的值
- java - 如何在 Hibernate Criteria API 中使用 row_number(或任何具有相同行为的东西)?
- html - 如何将此代码仅转换为 HTML?
- javascript - 具有多个标题的多个图像模式
- php - 菜单滚动问题
- react-native - React Native:屏幕顶部的额外空白空间
- c# - 调用 HttpContext.Response.WriteAsync() 后,ASP.NET Core Web API 无法返回 JSON 格式的对象?
- python - 以当前日期时间格式保存屏幕截图,
- python - 如何使用 python 循环来迭代具有不同参数的相同代码?