我正在尝试将Three.js项目迁移到TypeScript。当我尝试top compile它时,我会在Three.js repo上得到这个问题中引用的错误:
https://github.com/mrdoob/three.js/issues/17698
按照这些步骤,我安装了@types/offscreencanvas
并编辑了tsconfig.json,但现在我在尝试运行tsc
时得到以下输出:
node_modules/@types/offscreencanvas/index.d.ts(16,53): error TS2304: Cannot find name 'CanvasState'.
node_modules/@types/offscreencanvas/index.d.ts(16,66): error TS2304: Cannot find name 'CanvasTransform'.
node_modules/@types/offscreencanvas/index.d.ts(16,83): error TS2304: Cannot find name 'CanvasCompositing'.
node_modules/@types/offscreencanvas/index.d.ts(17,5): error TS2304: Cannot find name 'CanvasImageSmoothing'.
node_modules/@types/offscreencanvas/index.d.ts(17,27): error TS2304: Cannot find name 'CanvasFillStrokeStyles'.
node_modules/@types/offscreencanvas/index.d.ts(17,51): error TS2304: Cannot find name 'CanvasShadowStyles'.
node_modules/@types/offscreencanvas/index.d.ts(17,71): error TS2304: Cannot find name 'CanvasFilters'.
node_modules/@types/offscreencanvas/index.d.ts(17,86): error TS2304: Cannot find name 'CanvasRect'.
node_modules/@types/offscreencanvas/index.d.ts(17,98): error TS2304: Cannot find name 'CanvasDrawPath'.
node_modules/@types/offscreencanvas/index.d.ts(18,5): error TS2304: Cannot find name 'CanvasText'.
node_modules/@types/offscreencanvas/index.d.ts(18,34): error TS2304: Cannot find name 'CanvasImageData'.
node_modules/@types/offscreencanvas/index.d.ts(18,51): error TS2304: Cannot find name 'CanvasPathDrawingStyles'.
node_modules/@types/offscreencanvas/index.d.ts(18,76): error TS2304: Cannot find name 'CanvasTextDrawingStyles'.
node_modules/@types/offscreencanvas/index.d.ts(18,101): error TS2304: Cannot find name 'CanvasPath'.
node_modules/@types/offscreencanvas/index.d.ts(34,53): error TS2304: Cannot find name 'CanvasRenderingContext2DSettings'.
node_modules/@types/offscreencanvas/index.d.ts(36,90): error TS2304: Cannot find name 'ImageBitmapRenderingContext'.
node_modules/@types/offscreencanvas/index.d.ts(49,22): error TS2304: Cannot find name 'CanvasImageSource'.
node_modules/@types/offscreencanvas/index.d.ts(51,22): error TS2304: Cannot find name 'CanvasImageSource'.
node_modules/@types/offscreencanvas/index.d.ts(53,22): error TS2304: Cannot find name 'CanvasImageSource'.
node_modules/@types/offscreencanvas/index.d.ts(58,43): error TS2304: Cannot find name 'ImageBitmapSource'.
node_modules/@types/offscreencanvas/index.d.ts(59,43): error TS2304: Cannot find name 'ImageBitmapSource'.
node_modules/@types/offscreencanvas/index.d.ts(64,48): error TS2304: Cannot find name 'Transferable'.
node_modules/@types/offscreencanvas/index.d.ts(68,48): error TS2304: Cannot find name 'Transferable'.
node_modules/@types/offscreencanvas/index.d.ts(72,48): error TS2304: Cannot find name 'Transferable'.
node_modules/@types/offscreencanvas/index.d.ts(76,26): error TS2304: Cannot find name 'WindowOrWorkerGlobalScope'.
node_modules/@types/offscreencanvas/index.d.ts(76,53): error TS2304: Cannot find name 'WindowEventHandlers'.
node_modules/@types/offscreencanvas/index.d.ts(77,70): error TS2304: Cannot find name 'Transferable'.
node_modules/@types/offscreencanvas/index.d.ts(80,83): error TS2304: Cannot find name 'Transferable'.
node_modules/three/src/renderers/webvr/WebVRManager.d.ts(13,15): error TS2304: Cannot find name 'VRDisplay'.
node_modules/three/src/renderers/webvr/WebVRManager.d.ts(14,21): error TS2304: Cannot find name 'VRDisplay'.
下面是我的package.json
:
{...
"dependencies": {
"@types/webgl2": "0.0.5",
"offscreen-canvas": "^0.1.1"
},
"devDependencies": {
"@babel/core": "^7.8.3",
"@babel/preset-env": "^7.8.3",
"@types/gsap": "^1.20.2",
"@types/offscreencanvas": "^2019.6.1",
"@types/three": "^0.103.2",
"babelify": "^10.0.0",
"bootstrap": "^4.4.1",
"browserify": "^16.5.0",
"fancy-log": "^1.3.3",
"gsap": "^3.0.5",
"gulp": "^4.0.2",
"gulp-autoprefixer": "^7.0.1",
"gulp-babel": "^8.0.0-beta.2",
"gulp-cssnano": "^2.1.3",
"gulp-rename": "^2.0.0",
"gulp-sass": "^4.0.2",
"gulp-sourcemaps": "^2.6.5",
"gulp-tap": "^2.0.0",
"gulp-typescript": "^6.0.0-alpha.1",
"gulp-uglify-es": "^2.0.0",
"jquery": "^3.4.1",
"three": "^0.110.0",
"tsify": "^4.0.1",
"typescript": "^3.7.4",
"vinyl-buffer": "^1.0.1",
"vinyl-source-stream": "^2.0.0"
}
}
我的tsconfig.json
:
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"types": ["webgl2", "offscreencanvas"],
"lib": [
"ES2016",
"DOM",
"ES2015",
"ES2015.Iterable"
],
"outDir": "dist/js/projects"
},
"file": [
"src/js/projects/main.js"
]
}
3条答案
按热度按时间l7mqbcuq1#
这似乎是TypeScript版本问题,但
package.json
中的版本似乎是正确的。您是否尝试过从package.json
中的script
运行此操作,而不是通过您的终端?然后,您可以运行
npm run build
或yarn build
。pbpqsu0x2#
我在Pixi.js上也遇到了同样的问题,对我来说,安装@types/offscreencanvas没有帮助。所以我从它复制定义并将它们粘贴到main.d.ts中进行修复。
但要注意的是,如果你这样做,定义在某个时候可能会过时。我这样做是因为我使用Lerna monorepo + Angular,所以我很难跟踪问题,很遗憾找不到任何其他解决方案:(
2skhul333#
根据此https://github.com/aws/amazon-chime-sdk-js/issues/1909,我通过在tsconfig文件中添加
"types": ["jasmine","offscreencanvas"]
来修复此问题