10
votes

I am encountering a weird build issue with typescript and @types/react. I have two typescript config files: one for files which use react, and one for those that don't. When building the portion of my project which doesn't use react, I see the following error:

node_modules/@types/react/index.d.ts(3508,58): error TS2304: Cannot find name 'HTMLDialogElement'. node_modules/@types/react/index.d.ts(3508,78): error TS2304: Cannot find name 'HTMLDialogElement'. node_modules/@types/react/index.d.ts(3782,72): error TS2304: Cannot find name 'HTMLDialogElement'. node_modules/@types/react/index.d.ts(3782,92): error TS2304: Cannot find name 'HTMLDialogElement'.

I was able to reproduce the error with a minimal example:

node_modules/typescript/bin/tsc typescript/foo.ts --outDir static/js/src --module none

The file typescript/foo.ts is a minimal file I used to reproduce the problem, and is deliberately short:

function printNumber(n: number) {
    console.log(n);
}

let x = 3;
x *= 4;
printNumber(x);

Note that foo.ts does not have any references to react whatsoever. The weirdest part of this is when I uninstall @types/react, the error messages go away.

What's going on?

EDIT: I found this issue which manifests when tsc version > 2.3.2. I downgraded tsc to version 2.3.2 but the problem persists.

3
What version of typescript are you using? I had a similar problem, and it went away when I updated to 2.7.xZiggy
@Ziggy typescript v 2.3.2Daniel Kats
Getting the same problem.Bodman
can you provide a minimal example of this error? (with the configs)Gabriel Duarte
facing the same problem since today....messerbill

3 Answers

9
votes

As fair as I understand the typescript's policies, this is relative to the version you are using. When typescript 2.3.2 was out the definition for HTMLDialogElement was not included in @types/react, so you see this error. You can read more about this in this github issue.

Probably, even if you don't include React on your foo.ts, the typescript compiler will include and check all the definitions that you've got, even those in node_modules. This will explain why you have this error even without including React.

Now that I think about it, I don't event include the definitions that I wrote - but they're used by the transpiler.

I had the same issue on a project recently cloned yesterday; I fixed it by updating typescript to ^2.7.0.

0
votes

I had the same problem. tried all the upgrades and downgrades mentioned here.but, nothing worked for me. finally ended up commenting out the 'dialog' from line number 3782 and 3508 in node_modules/@types/react/index.d.ts This is only a quick fix.

0
votes

I had the same issue (latest create-react-app, with typescript version 2.5.3) and after I ejected the app (npm run eject) and updated typescript by hand to current version in package.json to current 2.7.2 this works again.

Seems to be some very strange bug (on Windows) cause my college (same installation) doesn't have this bug. When searching for this, you will find it appearing every 2 month or so, so that I guess, that it is not only this issue ( https://github.com/Microsoft/TypeScript/issues/16880 ) Duma pointed to, cause the project we're working on started somewhere in December.