简体   繁体   English

尝试使用 tsc file.ts 运行 Typescript 时出现 WebGL2RenderingContext 错误

[英]WebGL2RenderingContext Error when trying to run Typescript with tsc file.ts

I just installed Typescript using both npm and yarn on my Windows 10 machine, and when I run 'tsc file.ts' I get an error that says '582 declare var WebGL2RenderingContext'.我刚刚在我的 Windows 10 机器上使用 npm 和 yarn 安装了 Typescript,当我运行“tsc file.ts”时,我收到一条错误消息,显示“582 declare var WebGL2RenderingContext”。

It directs to the directory ../../AppData/Roaming/npm/node_modules/typescript/lib/lib.dom.d.ts:16485:13它指向目录 ../../AppData/Roaming/npm/node_modules/typescript/lib/lib.dom.d.ts:16485:13

Furthermore, It says 16485 declare var WebGL2RenderingContext: { 'WebGL2RendingContext'was also declared here.此外,它说 16485 声明 var WebGL2RenderingContext: { 'WebGL2RendingContext' 也在此处声明。 Found 1 error.发现 1 个错误。

Here is the screeshot from Node.js Command Prompt这是来自 Node.js 命令提示符的截图

在此处输入图片说明

我解决了执行此行的问题。

npm i --save @types/webgl2

If your declarations collide try to import declaration you need:如果您的声明发生冲突,请尝试导入您需要的声明:

import {WebGL2RenderingContext} from "webgl2"
const lol = (ctx: WebGL2RenderingContext)=>{/* do sth*/};

with @types/webgl2 problem is it have no exports, so you have to change it a bit: just add export before declare keywords. @types/webgl2 的问题是它没有导出,所以你必须稍微改变它:只需在declare关键字之前添加导出。

I could not have solved this problem without Zydnar's Help, Thanks to Him.没有 Zydnar 的帮助,我无法解决这个问题,感谢他。 After some deliberation, I decided to comment out the WebGL2 Rendering Function and It worked, It transpiled to javascript and I ended up using ts-node filename.ts to run the code.经过一番深思熟虑,我决定注释掉 WebGL2 渲染函数,它起作用了,它转译为 javascript,最后我使用 ts-node filename.ts 来运行代码。

Thanks once again to @Zydnar, You were very helpful.再次感谢@Zydnar,你很有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获(承诺)DOMException:无法在“WebGL2RenderingContext”上执行“texImage2D”:可能无法加载受污染的画布 - Uncaught (in promise) DOMException: Failed to execute 'texImage2D' on 'WebGL2RenderingContext': Tainted canvases may not be loaded 如何将Typescript(1.6或更高版本)字符串编译为javascript字符串? (不是file.ts到outputFile.js) - How can I compile typescript (1.6 or later) string to javascript string ? (Not file.ts to outputFile.js) 尝试运行 ts-node 脚本时出现未知文件扩展名“.ts”错误 - Unknown file extension ".ts" error appears when trying to run a ts-node script 将js文件导入ts时出现Typescript错误TS5055 - Typescript error TS5055 when importing js file into ts 无法在“WebGL2RenderingContext”上执行“texImage2D”。 CORS 已阻止从源“exampale.com”访问“imageurl.com”上的图像 - Failed to execute 'texImage2D' on 'WebGL2RenderingContext'. Access to image at 'imageurl.com' from origin 'exampale.com' has been blocked by CORS 文件更改时运行 tsc 时 nodemon 不工作 - run tsc with nodemon not working when file changes 为什么tsc编译输出一个在运行时抛出异常但ts-node正确运行ts文件的文件? - Why tsc compile output a file that throw exception on running but ts-node run the ts file correctly? 什么是WebGL2RenderingContext.attachShader? - What is WebGL2RenderingContext.attachShader? 如何显示表格,首先需要从file.ts获取数据,然后需要在html中写入静态数据,然后还需要从file.ts - how to show table, first need get data from file.ts, then need write static data in html, then also from file.ts 尝试导入 html 文件时出现 Typescript 错误 - Typescript error when trying to import an html file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM