WebGL2RenderingContext

WebGL2RenderingContext

我正在使用Reactjs来构建我的应用程序。当我运行我的应用程序时,出现以下错误。


  后续变量声明必须具有相同的类型。变量'WebGL2RenderingContext'的类型必须为'{new():WebGL2RenderingContext;原型:WebGL2RenderingContext;只读ACTIVE_ATTRIBUTES:数字;只读ACTIVE_TEXTURE:数字;只读ACTIVE_UNIFORMS:数字;只读ALIASED_LINE_WIDTH_RANGE:数字; ...更多554 ...;只读WAIT_FAILED:数字; },但此处的类型为'{new():WebGL2RenderingContext;原型:WebGL2RenderingContext;只读ACTIVE_ATTRIBUTES:数字;只读ACTIVE_TEXTURE:数字;只读ACTIVE_UNIFORMS:数字;只读ALIASED_LINE_WIDTH_RANGE:数字; ...更多555 ...;只读MAX_CLIENT_WAIT_TIMEOUT_WEBGL:数字; }'


在包中使用以下依赖项。

"@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软件包有关。尝试将"skipLibCheck": true添加到tsconfig.json文件。

更多信息:https://github.com/tensorflow/tfjs/issues/2007#issuecomment-529630217

07-28 11:45