如何阻止TypeScript编译器报告符号链接模块中的编译错误

问题描述 投票:0回答:1

我有一个由rush.js控制的monorepo,使用PNPM作为程序包管理器。

我曾经将所有共享模块预先编译为cjsesmdts目标。但是这种方法有一些缺陷,因此我决定将它们保留为原始资源,并将其在package.json中的主条目设置为"main": "./src/index.ts|x"。同时,我使用react-app-rewired告诉Webpack使用babel仅编译node_modules中的那些符号链接库,并且一切正常。笑话也很开心。

我所遇到的问题是,由于某种原因,当我运行tsc时,编译器会深入符号链接的本地程序包并报告很多问题(即使运行它们,它们即使没有问题也可以编译) C0])。

[tsc报告了TSForkWebpackPlugin的类似问题,但我使用create-react-appreportFiles config选项忽略了它们,并认为这是插件站点上的某种错误,但事实并非如此。

我向react-app-rewired添加了各种glob模式,例如exclude**/node_modules/@namespace/**node_modules/@namespace/**,但这些都不起作用。node_modules/@namespace也在那里。

我的"skipLibCheck": true供参考

tsconfig.json
typescript create-react-app symlink monorepo pnpm
1个回答
0
投票

目前,解决此问题的唯一方法是使{ "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"开始起作用,并且您不再遇到问题。

当然不是最佳选择,但是由于我们一直在使用Babel将TS编译为skipLibCheckcjs,所以我们现在无论如何都节省了很多时间,同时还具有监视模式和CRA多封装的其他功能宽。每个本地软件包的每次更改后都需要重建之前,该软件包不是增量的,例如在许多级别上很长且不方便。

有关实施细节的任何问题,请问我。

© www.soinside.com 2019 - 2024. All rights reserved.