如何解决如何禁用node_modules文件夹中特定库的libCheck和警告?
我不断从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
,但这并不能解决问题。
{
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文件夹错误的文件中
- 修补软件包
- 享受!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。