TypeError: Cannot find name DOMException
See original GitHub issueBug 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:
- Created a year ago
- Reactions:1
- Comments:11 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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
, andEventTarget
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 likeThis way is so much easier but might still cause issues.
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