question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compile error with @tensorflow/tfjs-backend-webgl for TS target > ES5

See original GitHub issue

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: -
  • TensorFlow.js installed from (npm or script link): npm
  • TensorFlow.js version: 2.7.0
  • CUDA/cuDNN version: -

Describe the problem When trying to build a typescript code that depends on @tensorflow/tfjs-backend-webgl, if the compilerOptions.target is above ES5 (i.e “ES2015”,“ES2016”,“ES2017”,“ES2018”,“ES2019”,“ES2020” or “ESNext”), you get the following compilation errors:

node_modules/typescript/lib/lib.dom.d.ts:16532:11 - error TS2430: Interface 'WebGL2RenderingContext' incorrectly extends interface 'WebGL2RenderingContextBase'.
  Types of property 'clearBufferfv' are incompatible.
    Type '(buffer: number, drawbuffer: number, values: ArrayLike<number> | Float32Array, srcOffset?: number) => void' is not assignable to type '{ (buffer: number, drawbuffer: number, values: Float32List, srcOffset?: number): void; (buffer: number, drawbuffer: number, values: Iterable<number>, srcOffset?: number): void; }'.
      Types of parameters 'values' and 'values' are incompatible.
        Type 'Iterable<number>' is not assignable to type 'ArrayLike<number> | Float32Array'.
          Type 'Iterable<number>' is missing the following properties from type 'Float32Array': BYTES_PER_ELEMENT, buffer, byteLength, byteOffset, and 25 more.

16532 interface WebGL2RenderingContext extends WebGL2RenderingContextBase, WebGL2RenderingContextOverloads, WebGLRenderingContextBase {
                ~~~~~~~~~~~~~~~~~~~~~~

node_modules/typescript/lib/lib.dom.d.ts:16532:11 - error TS2430: Interface 'WebGL2RenderingContext' incorrectly extends interface 'WebGL2RenderingContextOverloads'.
  Types of property 'uniform1fv' are incompatible.
    Type '(location: WebGLUniformLocation, data: ArrayLike<number> | Float32Array, srcOffset?: number, srcLength?: number) => void' is not assignable to type '{ (location: WebGLUniformLocation, data: Float32List, srcOffset?: number, srcLength?: number): void; (location: WebGLUniformLocation, data: Iterable<...>, srcOffset?: number, srcLength?: number): void; }'.
      Types of parameters 'data' and 'data' are incompatible.
        Type 'Iterable<number>' is not assignable to type 'ArrayLike<number> | Float32Array'.
          Type 'Iterable<number>' is not assignable to type 'Float32Array'.

16532 interface WebGL2RenderingContext extends WebGL2RenderingContextBase, WebGL2RenderingContextOverloads, WebGLRenderingContextBase {
                ~~~~~~~~~~~~~~~~~~~~~~

node_modules/typescript/lib/lib.dom.d.ts:16532:11 - error TS2430: Interface 'WebGL2RenderingContext' incorrectly extends interface 'WebGLRenderingContext'.
  Types of property 'uniform1fv' are incompatible.
    Type '(location: WebGLUniformLocation, data: ArrayLike<number> | Float32Array, srcOffset?: number, srcLength?: number) => void' is not assignable to type '{ (location: WebGLUniformLocation, v: Float32List): void; (location: WebGLUniformLocation, v: Iterable<number>): void; }'.
      Types of parameters 'data' and 'v' are incompatible.
        Type 'Iterable<number>' is not assignable to type 'ArrayLike<number> | Float32Array'.
          Type 'Iterable<number>' is not assignable to type 'Float32Array'.

16532 interface WebGL2RenderingContext extends WebGL2RenderingContextBase, WebGL2RenderingContextOverloads, WebGLRenderingContextBase {
                ~~~~~~~~~~~~~~~~~~~~~~


Found 3 errors.

Provide the exact sequence of commands / steps that you executed before running into the problem The error is easily reconstructed with the following:

  1. package.json:
{
	"name": "tfjs-ts-test",
	"version": "1.0.0",
	"description": "",
	"main": "index.js",
	"scripts": {
		"build": "tsc"
	},
	"author": "",
	"license": "ISC",
	"dependencies": {
		"@tensorflow/tfjs-backend-webgl": "^2.7.0",
		"@tensorflow/tfjs-core": "^2.7.0",
		"typescript": "^4.0.5"
	}
}
  1. tsconfig.json:
{
	"compilerOptions": {
		"target": "ES2015"
	}
}
  1. An empty index.ts
  2. npm install
  3. npm run build

Any other info / logs This partially relates to https://github.com/tensorflow/tfjs/issues/2007 but not the same issue

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
DBachiloVironitcommented, Sep 27, 2021

The errors still occur with the latest version of @tensorflow/tfjs-node and @tensorflow/tfjs-node-gpu.

  1. package.json
{
    "name": "tensorflow-test",
    "version": "0.0.1",
    "private": true,
    "description": "",
    "scripts": {
        "build": "./node_modules/typescript/bin/tsc --project ./tsconfig.json",
        "start": "node src/index.js"
    },
    "dependencies": {
        "@tensorflow/tfjs-node": "^3.9.0",
        "long": "^4.0.0",
        "nsfwjs": "^2.4.1"
    },
    "devDependencies": {
        "@types/long": "^4.0.1",
        "@types/node": "^16.10.1",
        "@types/webgl2": "^0.0.6",
        "typescript": "^4.4.3"
    }
}
  1. tsconfig.json
{
    "compilerOptions": {
        "target": "es6",
        "module": "commonjs",
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "types": [
            "node",
            "long"
        ]
    }
}

The errors are the same as in the first post.

About the `long` module Note that I also added `long` module and types because otherwise I get these errors:
node_modules/@tensorflow/tfjs-core/dist/hash_util.d.ts:2:49 - error TS2304: Cannot find name 'Long'.

export declare function hexToLong(hex: string): Long;
                                                  ~~~~

node_modules/@tensorflow/tfjs-core/dist/hash_util.d.ts:3:69 - error TS2304: Cannot find name 'Long'.

export declare function fingerPrint64(s: Uint8Array, len?: number): Long;
0reactions
google-ml-butler[bot]commented, Nov 12, 2022

Are you satisfied with the resolution of your issue? Yes No

Read more comments on GitHub >

github_iconTop Results From Across the Web

tsconfig for typescript to support es5 target throws error
My tsConfig.json is as below: { "compilerOptions": { "target":"es5", "module":"system", "emitDecoratorMetadata": true, ...
Read more >
Compiler Options - Microsoft Open Source
The target setting changes which JS features are downleveled or left intact. For example, an arrow function () => this will be turned...
Read more >
TSConfig Option: target - TypeScript
The target setting changes which JS features are downleveled and which are left intact. For example, an arrow function () => this will...
Read more >
Typescript - selecting proper target version - Dancing with CRM
ES5 vs ES2017. Let's review how the change only in the target version will improve our code. Below you can find sample ts...
Read more >
tsconfig.json - TypeScript Deep Dive - Gitbook
This way TypeScript will include all the .ts files in this directory (and sub ... "target": "es5", /* Specify ECMAScript target version: 'ES3'...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found