TypeScript Error Cannot find name 'DOMString'

Hi,
I just noticed this error after updating to the latest version of babylon.js (5.54.0), using typescript 4.9.3.

 ERROR(TypeScript)  Cannot find name 'DOMString'. Did you mean 'String'?
 FILE  node_modules/@babylonjs/core/Engines/engine.d.ts:1600:26

    1598 |
    1599 | class GPUPipelineError extends DOMException {
  > 1600 |     constructor(message: DOMString | undefined, options: GPUPipelineErrorInit);     
         |                          ^^^^^^^^^
    1601 |     readonly reason: GPUPipelineErrorReason;
    1602 | }
    1603 |

Maybe it’s just a typo?

1 Like

DOMString is not a typo. Check your tsconfig.json file. Context: javascript - Missing basic DOM types in TypeScript project - Stack Overflow

Still doesn’t seem to work after adding the lib compiler option. But why is this needed? As far as I can tell it just maps to a normal string (although I couldn’t find much info about DOMString). The message variable in the DOMException is just a normal string. I also can’t find any info in the documentation of babylonjs or the changelog that we need another setting like this in tsconfig.

Having same problem too just now. Can’t compile due to this, everything has come to a standstill…

Happened when I tried to add gltf exporter from the babylon/serializer package using npm.

Now after I remove it, this problem still stops me from compiling…

I guess it updated babylon.js at the same time.

Here are my current compiler options;

“compilerOptions”: {
“baseUrl”: “./”,
“outDir”: “./dist/out-tsc”,
“forceConsistentCasingInFileNames”: true,
“strictPropertyInitialization”: false,
“strict”: true,
“noImplicitOverride”: true,
“noPropertyAccessFromIndexSignature”: true,
“noImplicitReturns”: true,
“noFallthroughCasesInSwitch”: true,
“sourceMap”: true,
“declaration”: false,
“downlevelIteration”: true,
“experimentalDecorators”: true,
“moduleResolution”: “node”,
“importHelpers”: true,
“target”: “es2015”,
“module”: “es2020”,
“lib”: [
“es2018”,
“dom”
],
“useDefineForClassFields”: false,
},

I tried a lot of different suggestions for “lib” section, but they all give this error;

[ng]
[ng] Error: node_modules/@babylonjs/core/Engines/engine.d.ts:1600:26 - error TS2552: Cannot find name ‘DOMString’. Did you mean ‘String’?
[ng]
[ng] 1600 constructor(message: DOMString | undefined, options: GPUPipelineErrorInit);
[ng] ~~~~~~~~~
[ng]
[ng] node_modules/typescript/lib/lib.es5.d.ts:536:13
[ng] 536 declare var String: StringConstructor;
[ng] ~~~~~~
[ng] ‘String’ is declared here.
[ng]
[ng]
[ng]
[ng] × Failed to compile.

I have the same problem here after updating from 5.53.0 to 5.53.1 and I can make the problem appear and disappear by switching between these two versions.

I squeezed a tiny change here Fix asset Container crash with predicate by sebavan ¡ Pull Request #13720 ¡ BabylonJS/Babylon.js ¡ GitHub it should address the issue.

cc @Evgeni_Popov

3 Likes

Same error, can’t build application with the latest BabylonJS

Error: node_modules/@babylonjs/core/Engines/engine.d.ts:1600:26 - error TS2552: Cannot find name 'DOMString'. Did you mean 'String'?

1600     constructor(message: DOMString | undefined, options: GPUPipelineErrorInit);
                              ~~~~~~~~~

  node_modules/typescript/lib/lib.es5.d.ts:530:13
    530 declare var String: StringConstructor;
                    ~~~~~~
    'String' is declared here.

Any idea when this fix will be released on NPM?

You can create a ambient.d.ts or global.d.ts in your project root and just add a type for domstring and remove it whenever. …it doesnt matter.

1 Like

Not really understanding typescript I have no idea how to do this. Is this a common thing typescript people do?

Ok - so I did that and it worked. If anyone is like me here is the workaround;

create a file global.d.ts somewhere that will be imported - in angular this was the ‘src’ folder.

Add in this line;
type DOMString = string;

and rebuild.

1 Like

Now I am back to my original task - saving GLTF files; unfortunately this is still broken;

[ng] Error: node_modules/@babylonjs/serializers/glTF/2.0/glTFSerializer.d.ts:3:32 - error TS2307: Cannot find module ‘@babylonjs/core/Animations.js’ or its corresponding type declarations.
[ng]
[ng] 3 import type { Animation } from “@babylonjs/core/Animations.js”;
[ng] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

this seems to be a problem inside the serializer, so I am lost again…

I think you should create a new post, as this error does not match the subject of the current post (and this post is also marked as solved).

1 Like

Some fun facts…Angular ships with a hard coded version of typescript. This is because google verifies new tsc versions before they update their internal megarepo and angular’s ts version matches the typescript version used internally at google. So… the real issue is the ts settings shipping with angular i think.

To the op. Do you have “skipLibCheck: true” on? Thats supposed to skip type checking of dependencies, however if you’re in a monorepo that can get messed up. There are other settings that can mess it up for type declaration imports and interop with babel but il skip that for now. For monorepos or non standard folder layouts, You can set the include and exclude properties in your tsconfig . Typically include src and exclude node_modules, dist, build, but if you’re in a mono repo u can do a nested glob for something like packages/*/node_modules

3 Likes

Thanks for the input, I don’t have skipLibCheck set, maybe it’s another setting, but since it has been changed by babylonjs I would say: case closed :slight_smile: