Javascript TS2403:后续变量声明在react中必须具有相同的类型
我正在使用Reactjs构建我的应用程序。当我运行我的应用程序时,我得到以下错误 后续变量声明必须具有相同的类型。变量“WebGL2RenderingContext”的类型必须为“{new():WebGL2RenderingContext;原型:WebGL2RenderingContext;只读活动属性:编号;只读活动纹理:编号;只读活动线:编号;只读别名线\宽度\范围:编号;…554更多…;只读等待\失败:编号;}”,但这里有类型“{new():WebGL2RenderingContext;原型:WebGL2RenderingContext;只读活动\u属性:编号;只读活动\u纹理:编号;只读活动\u制服:编号;只读别名\u线宽\u范围:编号;…555更多…;只读最大\u客户端\u等待\u超时\u WEBGL:number;' 包中使用了以下依赖项Javascript TS2403:后续变量声明在react中必须具有相同的类型,javascript,reactjs,typescript,nodes,Javascript,Reactjs,Typescript,Nodes,我正在使用Reactjs构建我的应用程序。当我运行我的应用程序时,我得到以下错误 后续变量声明必须具有相同的类型。变量“WebGL2RenderingContext”的类型必须为“{new():WebGL2RenderingContext;原型:WebGL2RenderingContext;只读活动属性:编号;只读活动纹理:编号;只读活动线:编号;只读别名线\宽度\范围:编号;…554更多…;只读等待\失败:编号;}”,但这里有类型“{new():WebGL2RenderingContext;原
"@babel/core": "7.1.0",
"@babel/plugin-transform-react-jsx-source": "^7.0.0",
"@svgr/webpack": "2.4.1",
"@tensorflow/tfjs-converter": "^0.6.6",
"@tensorflow/tfjs-core": "^0.13.10",
"@types/elasticsearch": "^5.0.34",
"@types/http-aws-es": "^6.0.0",
"@types/lodash": "^4.14.118",
"@types/react": "^16.7.6",
"@types/react-dom": "^16.0.9",
"@types/react-router-dom": "^4.3.3",
"@types/react-webcam": "^1.1.0",
"@types/socket.io-client": "^1.4.32",
"antd-mobile": "^2.2.13",
"aws-sdk": "^2.476.0",
"axios": "^0.19.0",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "9.0.0",
"babel-jest": "23.6.0",
"babel-loader": "8.0.4",
"babel-plugin-named-asset-import": "^0.2.3",
"babel-preset-react-app": "^6.1.0",
"bfj": "6.1.1",
"case-sensitive-paths-webpack-plugin": "2.1.2",
"chalk": "2.4.1",
"css-loader": "1.0.0",
"dotenv": "6.0.0",
"dotenv-expand": "4.2.0",
"elasticsearch": "^16.1.1",
"eslint": "5.6.0",
"eslint-config-react-app": "^3.0.5",
"eslint-loader": "2.1.1",
"eslint-plugin-flowtype": "2.50.1",
"eslint-plugin-import": "2.14.0",
"eslint-plugin-jsx-a11y": "6.1.2",
"eslint-plugin-react": "7.11.1",
"file-loader": "2.0.0",
"firebase": "^6.2.0",
"fork-ts-checker-webpack-plugin-alt": "0.4.14",
"fs-extra": "7.0.0",
"google-maps-react": "^2.0.2",
"html-webpack-plugin": "4.0.0-alpha.2",
"http-aws-es": "^6.0.0",
"husky": "^1.1.4",
"identity-obj-proxy": "3.0.0",
"jest": "23.6.0",
"jest-pnp-resolver": "1.0.1",
"jest-resolve": "23.6.0",
"lint-staged": "^8.0.4",
"lodash": "^4.17.11",
"mini-css-extract-plugin": "0.4.3",
"moment": "^2.24.0",
"node-sass": "^4.12.0",
"optimize-css-assets-webpack-plugin": "5.0.1",
"pnp-webpack-plugin": "1.1.0",
"postcss-flexbugs-fixes": "4.1.0",
"postcss-loader": "3.0.0",
"postcss-preset-env": "6.0.6",
"postcss-safe-parser": "4.0.1",
"prettier": "^1.15.2",
"react": "^16.6.3",
"react-app-polyfill": "^0.1.3",
"react-dev-utils": "^6.1.1",
"react-dom": "^16.6.3",
"react-router-dom": "^5.0.1",
"react-webcam": "^1.1.1",
"resolve": "1.8.1",
"sass-loader": "7.1.0",
"save": "^2.4.0",
"socket.io-client": "^2.2.0",
"style-loader": "0.23.0",
"terser-webpack-plugin": "1.1.0",
"tslint-config-prettier": "^1.16.0",
"typescript": "^3.1.6",
"url-loader": "1.1.1",
"webpack": "4.19.1",
"webpack-dev-server": "3.1.9",
"webpack-manifest-plugin": "2.0.4",
"workbox-webpack-plugin": "3.6.3"
tsconfig文件:
{
"compilerOptions": {
"outDir": "build",
"module": "esnext",
"target": "es5",
"lib": ["es2017", "es6", "dom"],
"sourceMap": true,
"allowJs": true,
"jsx": "react",
"moduleResolution": "node",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"allowSyntheticDefaultImports": true,
"noUnusedLocals": true,
"baseUrl": ".",
"rootDir": ".",
"paths": {
"@/*": ["src/*"],
"@components/*": ["src/components/*"],
}
},
"exclude": [
"node_modules/",
"build/",
"scripts/",
"acceptance-tests/",
"webpack/",
"jest/",
"src/setupTests.ts",
"public/",
"config/"
]
}
为什么会发生这种错误?我怎样才能解决这个问题 我也有同样的问题。这个问题似乎与Tensforflow js使用的webgl2包有关。尝试向tsconfig.json文件添加
“skipLibCheck”:true
更多信息:跳过库检查,可能会产生比解决问题更多的问题: $npm i@types/webgl2-D
…以对齐包类型 你能提供更多的上下文来解释这个错误吗?@MichaelSorensen更新了我的问题如果你认为这个问题是你的包之一,我建议使用消除过程来找到导致问题的那个。然而,99.99%的时候我遇到了错误,这是我的错。您是否添加了导致此错误的代码?请提供您的tsconfig。json@DanPantry有问题的更新