[英]How to ignore typescript errors when compile by webpack production mode
網絡包 4.41.2
打字稿 3.7.2
當我通過webpack開發模式編譯文件時,沒有問題。 但是我用生產模式編譯的時候,錯誤很多,編譯不了。
找到在 webpack 通過生產模式編譯時如何忽略打字稿錯誤的方法
▼webpack.config.js(js部分)
{
mode: "development",
entry: "./src/index.tsx",
output: {
path: `${__dirname}/dist`,
filename: "index.js"
},
module: {
rules: [
{
test: /\.tsx?$/,
use: "ts-loader"
},
{
test: /\.svg$/,
loader: "react-svg-loader",
options: {
svgo: {
plugins: [
{ removeTitle: false }
],
floatPrecision: 2
}
}
},
{
test: /\.(vert|frag|glsl)$/,
use: {
loader: 'webpack-glsl-loader'
}
}
]
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".json"]
},
},
▼ tsconfig
{
"compilerOptions": {
"sourceMap": false,
"target": "es5",
"module": "es2015",
"jsx": "react",
"moduleResolution": "node",
"lib": [
"es2019",
"dom"
],
"removeComments": true,
"noUnusedLocals": false
}
}
ERROR in /var/www/hoge/src/index.tsx
[tsl] ERROR in /var/www/hoge/src/index.tsx(56,33)
TS2322: Type '(page: any) => void' is not assignable to type 'void'.
ERROR in /var/www/hoge/src/about/index.tsx
[tsl] ERROR in /var/www/hoge/src/about/index.tsx(15,48)
TS2339: Property 'appRef' does not exist on type 'About'.
ERROR in /var/www/hoge/src/gallery/index.tsx
[tsl] ERROR in /var/www/hoge/src/gallery/index.tsx(8,27)
TS2307: Cannot find module './picturesData'.
ERROR in /var/www/hoge/src/gallery/index.tsx
[tsl] ERROR in /var/www/hoge/src/gallery/index.tsx(9,9)
TS2529: Duplicate identifier 'Promise'. Compiler reserves name 'Promise' in top level scope of a module containing async functions.
...and other almost similar 40 errors
・在 Internet 上檢查類似的帖子,例如在 Webpack-dev-server 中忽略打字稿錯誤如何使用 webpack 忽略打字稿錯誤? 但這對我沒有幫助
・將此代碼添加到 tsconfig.js
"no-consecutive-blank-lines": false,
"no-unused-variable": false,
但錯誤“未知的編譯器選項”
使用ignoreDiagnostics
忽略某些 TypeScript 錯誤
{
test: /\.tsx?$/,
use: "ts-loader",
options: {
ignoreDiagnostics: [2322]
}
},
module.exports = {
...
module: {
rules: [
{
test: /\.tsx?$/,
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: true
}
}
]
}
]
}
}
在所有文件中添加// @ts-nocheck
,並編譯。 (我認為還有其他更好的方法)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.