typescript - 如何阻止 TypeScript 编译器报告符号链接模块中的编译错误
问题描述
我有一个由 rush.js 控制的 monorepo,PNPM 作为包管理器。
我曾经将所有共享模块预编译成cjs
, esm
,dts
目标。但是这种方法有一些缺陷,所以我决定将它们保留为未触及的来源,并将它们的主要条目设置package.json
为"main": "./src/index.ts|x"
. 同时,我曾经react-app-rewired
告诉 Webpack 只编译那些node_modules
使用 babel 的符号链接库,并且一切正常。杰斯特也很高兴。
我遇到的问题是,当我tsc
出于某种原因运行编译器时,编译器会深入到符号链接的本地包并报告很多问题(即使运行它们的编译器也没有任何问题tsc
)。
TSForkWebpackPlugin
报告了类似的问题,但我使用配置选项create-react-app
忽略了它们,并认为这是插件站点上的某种错误,但似乎不是。reportFiles
react-app-rewired
我添加了各种exclude
喜欢的 glob 模式,**/node_modules/@namespace/**
但这些都不起作用。
也有吗?node_modules/@namespace/**
node_modules/@namespace
"skipLibCheck": true
我tsconfig.json
的供参考
{
"compilerOptions": {
"incremental": true,
"baseUrl": "src",
"downlevelIteration": true,
"lib": ["esnext", "dom", "dom.iterable"],
"module": "esnext",
"target": "esnext",
"sourceMap": true,
"allowJs": true,
"esModuleInterop": true,
"isolatedModules": true,
"jsx": "preserve",
"moduleResolution": "node",
"forceConsistentCasingInFileNames": false,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"noUnusedParameters": true,
"noUnusedLocals": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"skipLibCheck": true,
"noEmit": true,
"preserveSymlinks": true,
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"strict": true
},
"exclude": [
"node_modules"
],
"include": ["src"]
}
解决方案
目前,解决这个问题的唯一方法是让tsc
符号链接项目是通过添加"types": "./types/index.d.ts"
或类似方式编译的库,并发出真实的声明。然后,我假设因为他认为这是一个图书馆skipLibCheck
开始工作并且你不再遇到问题了。
当然它不是超级优化的,但是由于我们一直在将 TS 编译到cjs
并esm
使用 Babel,所以无论如何我们现在都节省了大量时间,同时还拥有监视模式和 CRA 多包范围内的其他东西。在每次更改每个本地包之后都需要重新构建之前,这不是增量的,例如在许多级别上很长且不方便。
有关实施细节的任何问题,请问我。
推荐阅读
- html - 使用 div 和 span 进行 html 页面设计
- java - 从 InelliJ 自动导入功能中排除类/包
- node.js - Node.js child_process 中的错误代码 255 是什么意思
- django - Django 批量更新两个表的数据
- python - 从循环中保存多个数据帧
- c# - TLS 致命:握手失败
- react-native - 在 react-native-video 中播放 youtube 视频
- ios - 无法使用 Xcode 10.2+ 构建的通用(胖)框架编译模拟器构建
- python-3.x - 使用python同时在多个文件上运行一个函数
- python - 如何为python安装解析器库