[英]How to stop TypeScript compiler from reporting compilation errors in symlinked modules
I have a monorepo controlled by rush.js with PNPM as a package manager.我有一个由 rush.js 控制的 monorepo,PNPM 作为 package 管理器。
I used to have all shared modules to be precompiled into cjs
, esm
, dts
targets.我曾经将所有共享模块预编译为
cjs
、 esm
、 dts
目标。 But this approach has some flaws, so I decided to keep them as untouched sources, and set their main entry in package.json
to be "main": "./src/index.ts|x"
.但是这种方法有一些缺陷,所以我决定将它们保留为未触及的来源,并将
package.json
中的主要条目设置为"main": "./src/index.ts|x"
。 At the same time, I used react-app-rewired
to tell Webpack to compile only those symlinked libraries from node_modules
using babel and everything works perfectly.同时,我使用
react-app-rewired
rewired 告诉node_modules
的符号链接库,一切正常。 Jest is happy too.杰斯特也很高兴。
The problem that I've got tho, is that when I run tsc
for some reason compiler goes deep into the symlinked local packages and reports A LOT of issues (even tho they are compiling without any issues if you run their tsc
).我遇到的问题是,当我出于某种原因运行
tsc
时,编译器会深入到符号链接的本地包中并报告很多问题(即使运行他们的tsc
时它们编译时也没有任何问题)。
TSForkWebpackPlugin
reported similar issues for create-react-app
but I ignored them using reportFiles
config option using react-app-rewired
and thought it was some sort of bug on plugin site, but it seems it's not. TSForkWebpackPlugin
报告了create-react-app
类似问题,但我使用react-app-rewired
rewired 的reportFiles
配置选项忽略了它们,并认为这是插件站点上的某种错误,但似乎不是。
I added all sorts of glob patterns to exclude
like **/node_modules/@namespace/**
and node_modules/@namespace/**
and node_modules/@namespace
none of those worked.我添加了各种 glob 模式以
exclude
**/node_modules/@namespace/**
和node_modules/@namespace/**
和node_modules/@namespace
这些都不起作用。 "skipLibCheck": true
is there too. "skipLibCheck": true
也有。
My tsconfig.json
for reference我的
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"]
}
The only solution to this problem, for now, is to make tsc
think that symlinked projects are compiled libraries by adding "types": "./types/index.d.ts"
or similar and emit declarations for real.目前,解决这个问题的唯一方法是让
tsc
认为符号链接项目是编译库,方法是添加"types": "./types/index.d.ts"
或类似的,并发出真实的声明。 Then, I assume since he thinks it's a library skipLibCheck
starts to work and you're not getting issues anymore.然后,我假设因为他认为这是一个库
skipLibCheck
开始工作并且您不再遇到问题。
Surely it's not super optimal, but since we've been getting TS compiled to cjs
and esm
using Babel, we're saving a lot of time now anyway, while also having watch mode and other stuff from CRA multipackage wide.当然它不是超级优化的,但是由于我们一直在使用 Babel 将 TS 编译为
cjs
和esm
,所以无论如何我们现在都节省了很多时间,同时还拥有监视模式和 CRA 多包范围内的其他东西。 Before rebuild was required after each change for each local package which is not incremental eg long and inconvenient on many levels.每个本地 package 每次更改后都需要重建之前,这不是增量的,例如在许多级别上很长且不方便。
Any questions about details of implementation, please, ask me.任何关于实施细节的问题,请问我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.