我一直在嘗試查看是否無法讓我的腳本構建忽略node_modules(特別是React)。我的tsconfig.json告訴它忽略該文件夾,但它仍在編譯中,我不知道爲什麼。我懷疑也許是因爲它被包含文件中的文件導入,或許?輸入反應node_module中的Typescript編譯錯誤,即使它在tsconfig.json中被排除
這裏的錯誤,其中有很多的例子:
ERROR in /Users/rw3iss/Sites/site/src/project/public/node_modules/@types/react/index.d.ts
(3606,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'feTile' must be of type 'SVGProps<SVGFETileElement>', but here has type 'SVGProps<SVGFETileElement>'.
我tsconfig.json看起來是這樣的:
{
"compilerOptions": {
"jsx": "react",
"target": "es6",
"module": "commonjs",
"noEmitOnError": true,
"noImplicitAny": false,
"experimentalDecorators": true,
"sourceMap": true,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noFallthroughCasesInSwitch": true,
"allowJs": true,
"outDir": "build",
"noResolve": false,
"moduleResolution": "node",
"typeRoots": [
"./node_modules/@types",
"./secure/node_modules/@types",
"./public/node_modules/@types"
],
"types": [ "react" ]
},
"filesGlob": [
],
"include": [
"secure/src/**/*",
"public/react_src/**/*"
],
"exclude": [
"node_modules/**/*",
"public/node_modules/**/*",
"secure/node_modules/**/*",
"public/dist"
],
"types": [ "react" ]
}
我試圖用的WebPack/TS編譯它-loader,和我的WebPack配置爲:
var webpack = require('webpack');
var path = require('path');
var BUILD_DIR = path.resolve(__dirname, 'build');
var APP_DIR = path.resolve(__dirname, 'src');
var config = {
entry: {
app: [
APP_DIR + '/react_src/Secure.tsx',
APP_DIR + '/react_src/DicomViewer.tsx'
]
},
output: {
publicPath: '/',
path: BUILD_DIR, // 'dist'
filename: '[name].js', // 'index.js'
//libraryTarget: 'umd'
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
modules: [ 'node_modules', 'src' ]
},
module: {
rules: [
{
test: /\.(t|j)sx?$/,
include: APP_DIR,
exclude: [
path.resolve(__dirname, 'node_modules'),
'../public/node_modules',
'../node_modules'
],
loader: ['ts-loader']
}
]
}
};
module.exports = config;
誰能告訴我,爲什麼這些錯誤發生,如何可能以避免它們和可能在導入的node_modules中彈出的其他錯誤?
更新: 我刪除一切在 'typeRoots',並設置 '類型' 設置爲[]:
"typeRoots": [],
"types": []
但它仍然拋出了同樣的錯誤。我只是想了解爲什麼...
嗨Shaun,謝謝。我確實嘗試過,但無濟於事。我刪除了類型根目錄中的所有內容,並將所有類型都放在一起,但仍然拋出相同的錯誤。我將它添加到上面的描述中。 –