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.

TypeError: Cannot find name DOMException

See original GitHub issue

Bug Description

Missing DOMException, Event and other types

Reproducible By

// tsconfrig.json
{
  "compilerOptions": {
    "module": "CommonJS",
    "moduleResolution": "Node",
    "target": "ES2020",
    "lib": ["ES2020"],
    "rootDir": "src",
    "outDir": "out",
    "strict": true,
    "esModuleInterop": true,
    "sourceMap": true
  },
  "include": ["src"]
}

run

tsc -p ./

Expected Behavior

Compilation passed

Logs & Screenshots

node_modules/undici/types/filereader.d.ts:5:41 - error TS2304: Cannot find name 'EventTarget'.

5 export declare class FileReader extends EventTarget {
                                          ~~~~~~~~~~~

node_modules/undici/types/filereader.d.ts:27:19 - error TS2304: Cannot find name 'DOMException'.

27   readonly error: DOMException | null
                     ~~~~~~~~~~~~

node_modules/undici/types/filereader.d.ts:37:44 - error TS2304: Cannot find name 'EventInit'.   

37 export interface ProgressEventInit extends EventInit {
                                              ~~~~~~~~~

node_modules/undici/types/filereader.d.ts:43:44 - error TS2304: Cannot find name 'Event'.       

43 export declare class ProgressEvent extends Event {
                                              ~~~~~

[11:46:51] Found 4 errors. Watching for file changes.

Environment

Node v16.18.0

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
KhafraDevcommented, Nov 7, 2022

This is something that we should fix, considering this is causing issues for other people.

We need to add EventInit (this is easy), DOMException, Event, and EventTarget while not conflicting with node v18+ types. In v16, these types aren’t available. In v18, some of these might not be available - not sure.

OR, we could any the types if not available… something like

export type DOMException = typeof globalThis extends { DOMException: infer T }
  ? T
  : any

This way is so much easier but might still cause issues.

0reactions
KhafraDevcommented, Oct 31, 2022

DOMException wasn’t exposed until v17 so we use a hack to get it in node 16. You can get it by doing: https://github.com/nodejs/undici/blob/bc1ee0cf768a8a18228807960ab050cefd8c273f/lib/fetch/constants.js#L66-L74

or you could use node-domexception, which uses a different hack, but it’s in the form of an npm package instead

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript getting error TS2304: cannot find name ' require'
I am getting the error "TS2304: Cannot find name 'require' " when I attempt to transpile a simple TypeScript Node.js page. I have...
Read more >
DOMException - Web APIs | MDN
Constructor. DOMException(). Returns a DOMException object with a specified message and name. ... The object cannot be found here.
Read more >
domexception - npm
DOMException. This package implements the DOMException class, from web browsers. It exists in service of jsdom and related packages.
Read more >
Node.js v19.3.0 Documentation
reg: /abc/i, }, ); // Fails due to the different `message` and `name` properties: assert.throws( () => { const otherErr = new Error('Not...
Read more >
DOM - DOMException Object - Tutorialspoint
Error Types ; 5. NoModificationAllowedError. The object cannot be modified. (Legacy code value: 7 and legacy constant name: NO_MODIFICATION_ALLOWED_ERR) ; 6.
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