Fresh project.
- I create the project with
ng new
, - then immediately upgrade to angular 19 with
ng upgrade @angular/core@19 @angular/cli@19
. - I then install WebGPU type bindings
npm install --save-dev @webgpu/types
. - I wipe out the
appponent.html
file - I add to
tsconfig.json
the typeroots for webgpu:"typeRoots:["@webgpu/types"]
- In
appponent.ts
, I haveAppComponent
inherit fromOnInit
and implementngOnInit
solely with the action of assigning a local variablegpu
with the valuenavigator.gpu
. - I run
npm start
to run the web server
Instead of successfully building, I get the following error from the terminal:
✘ [ERROR] TS2339: Property 'gpu' does not exist on type 'Navigator'. [plugin angular-compiler]
src/app/appponent.ts:11:24:
11 │ let gpu = navigator.gpu;
╵ ~~~
What have I done wrong?
Files, for reference (only files that have been altered from the stock files angular creates):
tsconfig.json
:
/* To learn more about Typescript configuration file: .html. */
/* To learn more about Angular compiler options: /reference/configs/angular-compiler-options. */
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"skipLibCheck": true,
"esModuleInterop": true,
"sourceMap": true,
"declaration": false,
"experimentalDecorators": true,
"moduleResolution": "bundler",
"importHelpers": true,
"target": "ES2022",
"module": "ES2022",
"useDefineForClassFields": false,
"lib": [
"ES2022",
"dom"
],
"typeRoots":["./node_modules/@webgpu/types"]
},
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}
appponent.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './appponent.html',
styleUrl: './appponent.scss'
})
export class AppComponent implements OnInit{
title = 'webgpuhello';
public ngOnInit() {
let gpu = navigator.gpu;
}
}
appponent.html
: [is a blank file]
Fresh project.
- I create the project with
ng new
, - then immediately upgrade to angular 19 with
ng upgrade @angular/core@19 @angular/cli@19
. - I then install WebGPU type bindings
npm install --save-dev @webgpu/types
. - I wipe out the
appponent.html
file - I add to
tsconfig.json
the typeroots for webgpu:"typeRoots:["@webgpu/types"]
- In
appponent.ts
, I haveAppComponent
inherit fromOnInit
and implementngOnInit
solely with the action of assigning a local variablegpu
with the valuenavigator.gpu
. - I run
npm start
to run the web server
Instead of successfully building, I get the following error from the terminal:
✘ [ERROR] TS2339: Property 'gpu' does not exist on type 'Navigator'. [plugin angular-compiler]
src/app/appponent.ts:11:24:
11 │ let gpu = navigator.gpu;
╵ ~~~
What have I done wrong?
Files, for reference (only files that have been altered from the stock files angular creates):
tsconfig.json
:
/* To learn more about Typescript configuration file: https://www.typescriptlang./docs/handbook/tsconfig-json.html. */
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"skipLibCheck": true,
"esModuleInterop": true,
"sourceMap": true,
"declaration": false,
"experimentalDecorators": true,
"moduleResolution": "bundler",
"importHelpers": true,
"target": "ES2022",
"module": "ES2022",
"useDefineForClassFields": false,
"lib": [
"ES2022",
"dom"
],
"typeRoots":["./node_modules/@webgpu/types"]
},
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}
appponent.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './appponent.html',
styleUrl: './appponent.scss'
})
export class AppComponent implements OnInit{
title = 'webgpuhello';
public ngOnInit() {
let gpu = navigator.gpu;
}
}
appponent.html
: [is a blank file]
Share
Improve this question
edited Mar 31 at 8:13
DarkBee
15.5k8 gold badges72 silver badges117 bronze badges
asked Mar 31 at 5:27
XiremaXirema
19.9k4 gold badges36 silver badges70 bronze badges
2
- According to Mozilla's Navigator GPU Page, WebGPU isn't currently supported for NodeJS. – radical7 Commented Mar 31 at 5:40
- This question is about a compile time issue, not a runtime one. – Matthieu Riegler Commented Mar 31 at 14:40
1 Answer
Reset to default 2In your tsconfig.json
"types":["@webgpu/types"]
instead of using typeRoots
.
Per the docs,
If
typeRoots
is specified, only packages undertypeRoots
will be included. For example:
Which is not what you want.
Also note that web gpu might not be enabled on your browser. For Chrome there are several conditions listed here.
- WebGPU requires Chrome 113 or greater on ChromeOS, macOS, Windows and Chrome 121 or greater on Android. Check your version at
chrome://version
and update if necessary. - WebGPU is accessible only to secure contexts (https or localhost)
- On Linux it's behind a feature flag.