如何禁用 node_modules 文件夹中特定库的 libCheck 和警告?
How to disable libCheck and warnings for a specific library in the node_modules folder?
我一直收到来自 node_modules 库中 TS 文件的警告,我不想看到这些警告。
有问题的库在这里:https://github.com/xdan/jodit
我像这样在 app.tsx 中导入库:
import { IControlType, IJodit, Jodit } from 'jodit';
这是我的tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
// "forceConsistentCasingInFileNames": true,
"jsx": "react",
"lib": ["dom", "dom.iterable", "esnext"],
"module": "esnext",
"moduleResolution": "node",
"noErrorTruncation": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"outDir": "build",
"resolveJsonModule": true,
"paths": {
"src/*": ["src/*"]
},
"sourceMap": true,
"strictNullChecks": false,
"suppressImplicitAnyIndexErrors": true,
"target": "es5"
},
"include": ["src"],
"exclude": [
"**/*.spec.ts",
"**/node_modules",
"build",
"node_modules",
"scripts",
"src/serviceWorker.ts",
"src/vendors/**/*"
]
}
现在,我已经尝试 skipLibCheck: true
,但没有解决问题。
- 我真的不想仅仅因为一个包就禁用所有的 libCheck
- 反正没用,因为如果我没理解错,即使我跳过了lib check,TS也会检查文件,因为文件是导入到我的项目中
在我的 webpack 配置中我有这个:
{
test: /\.(js|mjs|jsx|ts|tsx)$/,
enforce: 'pre',
use: [
{
options: {
cache: true,
eslintPath: require.resolve('eslint'),
formatter: require.resolve('react-dev-utils/eslintFormatter'),
resolvePluginsRelativeTo: __dirname,
emitError: isEnvProduction,
},
loader: require.resolve('eslint-loader'),
},
],
include: paths.appSrc,
}
new ForkTsCheckerWebpackPlugin({
typescript: resolve.sync('typescript', {
basedir: paths.appNodeModules,
}),
async: isEnvDevelopment,
useTypescriptIncrementalApi: true,
checkSyntacticErrors: true,
resolveModuleNameModule: process.versions.pnp ? `${__dirname}/pnpTs.js` : undefined,
resolveTypeReferenceDirectiveModule: process.versions.pnp
? `${__dirname}/pnpTs.js`
: undefined,
tsconfig: paths.appTsConfig,
reportFiles: [
'**',
'!**/__tests__/**',
'!**/?(*.)(spec|test).*',
'!**/src/setupProxy.*',
'!**/src/setupTests.*',
],
silent: true,
// The formatter is invoked directly in WebpackDevServerUtils during development
formatter: isEnvProduction ? typescriptFormatter : undefined,
})
我不知道这里是否有办法忽略这个库的错误?
我在控制台中遇到的错误如下:
react/assets/node_modules/jodit/src/modules/toolbar/collection/editor-collection.ts(40, 4)
Type 'boolean | void' is not assignable to type 'boolean'
好吧,没有好的干净的方法可以做到这一点,但是,我确实找到了让它工作的方法。
因为我不想从另一个库的文件中进行任何验证,所以我决定将 // @ts-nocheck
添加到发出警告的文件中。
现在,您必须进入 node_modules 文件夹并找到该库,并将该注释添加到导致您出现问题的所有 .ts
文件的第一行。
之后您想使用 https://github.com/ds300/patch-package#readme 模块来修补库,这样您就不必在每次安装库时手动进行这些更改。
最后一步,如果您愿意,请修复库中的错误并提交拉取请求。
所以:
- 对 node_modules 文件夹中导致错误的文件添加忽略注释
- 修补程序包
- 尽情享受吧!
我一直收到来自 node_modules 库中 TS 文件的警告,我不想看到这些警告。
有问题的库在这里:https://github.com/xdan/jodit
我像这样在 app.tsx 中导入库:
import { IControlType, IJodit, Jodit } from 'jodit';
这是我的tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
// "forceConsistentCasingInFileNames": true,
"jsx": "react",
"lib": ["dom", "dom.iterable", "esnext"],
"module": "esnext",
"moduleResolution": "node",
"noErrorTruncation": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"outDir": "build",
"resolveJsonModule": true,
"paths": {
"src/*": ["src/*"]
},
"sourceMap": true,
"strictNullChecks": false,
"suppressImplicitAnyIndexErrors": true,
"target": "es5"
},
"include": ["src"],
"exclude": [
"**/*.spec.ts",
"**/node_modules",
"build",
"node_modules",
"scripts",
"src/serviceWorker.ts",
"src/vendors/**/*"
]
}
现在,我已经尝试 skipLibCheck: true
,但没有解决问题。
- 我真的不想仅仅因为一个包就禁用所有的 libCheck
- 反正没用,因为如果我没理解错,即使我跳过了lib check,TS也会检查文件,因为文件是导入到我的项目中
在我的 webpack 配置中我有这个:
{
test: /\.(js|mjs|jsx|ts|tsx)$/,
enforce: 'pre',
use: [
{
options: {
cache: true,
eslintPath: require.resolve('eslint'),
formatter: require.resolve('react-dev-utils/eslintFormatter'),
resolvePluginsRelativeTo: __dirname,
emitError: isEnvProduction,
},
loader: require.resolve('eslint-loader'),
},
],
include: paths.appSrc,
}
new ForkTsCheckerWebpackPlugin({
typescript: resolve.sync('typescript', {
basedir: paths.appNodeModules,
}),
async: isEnvDevelopment,
useTypescriptIncrementalApi: true,
checkSyntacticErrors: true,
resolveModuleNameModule: process.versions.pnp ? `${__dirname}/pnpTs.js` : undefined,
resolveTypeReferenceDirectiveModule: process.versions.pnp
? `${__dirname}/pnpTs.js`
: undefined,
tsconfig: paths.appTsConfig,
reportFiles: [
'**',
'!**/__tests__/**',
'!**/?(*.)(spec|test).*',
'!**/src/setupProxy.*',
'!**/src/setupTests.*',
],
silent: true,
// The formatter is invoked directly in WebpackDevServerUtils during development
formatter: isEnvProduction ? typescriptFormatter : undefined,
})
我不知道这里是否有办法忽略这个库的错误?
我在控制台中遇到的错误如下:
react/assets/node_modules/jodit/src/modules/toolbar/collection/editor-collection.ts(40, 4)
Type 'boolean | void' is not assignable to type 'boolean'
好吧,没有好的干净的方法可以做到这一点,但是,我确实找到了让它工作的方法。
因为我不想从另一个库的文件中进行任何验证,所以我决定将 // @ts-nocheck
添加到发出警告的文件中。
现在,您必须进入 node_modules 文件夹并找到该库,并将该注释添加到导致您出现问题的所有 .ts
文件的第一行。
之后您想使用 https://github.com/ds300/patch-package#readme 模块来修补库,这样您就不必在每次安装库时手动进行这些更改。
最后一步,如果您愿意,请修复库中的错误并提交拉取请求。
所以:
- 对 node_modules 文件夹中导致错误的文件添加忽略注释
- 修补程序包
- 尽情享受吧!