Cannot find name 'MessageEvent'
See original GitHub issueI changed the value for lib
in my “tsconfig.json” from ["dom", "es2017"]
to ["es2017"]
because I am working on a Node.js-only project (no Browser environment). Unfortunately, this broke my integration with “reconnecting-websocket”. I am getting now the following errors:
##[error]node_modules/reconnecting-websocket/dist/events.d.ts(20,14): error TS2304: Cannot find name 'MessageEvent'.
##[error]node_modules/reconnecting-websocket/dist/events.d.ts(30,22): error TS2304: Cannot find name 'MessageEvent'.
##[error]node_modules/reconnecting-websocket/dist/events.d.ts(31,30): error TS2304: Cannot find name 'MessageEvent'.
##[error]node_modules/reconnecting-websocket/dist/reconnecting-websocket.d.ts(24,54): error TS2304: Cannot find name 'Blob'.
##[error]node_modules/reconnecting-websocket/dist/reconnecting-websocket.d.ts(54,17): error TS2304: Cannot find name 'BinaryType'.
##[error]node_modules/reconnecting-websocket/dist/reconnecting-websocket.d.ts(96,25): error TS2304: Cannot find name 'MessageEvent'.
When digging into “reconnecting-websocket.ts”, I realized that it expects “MessageEvent” to come from TypeScript’s internal “DOM” library which is not available in a Node.js environment.
On Node.js the MessageEvent
can be retrieved from the “ws” package:
import WebSocket, {MessageEvent} from 'ws';
Can this information be included in “reconnecting-websocket”?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:6 (2 by maintainers)
Top Results From Across the Web
TypeScript complains about DOM types when compiling for ...
d.ts(10,29): error TS2304: Cannot find name 'MessageEvent'. node_modules/rxjs/observable/dom/WebSocketSubject.d.ts( ...
Read more >node.js - RxJS5 TypeScript typings fail - Stack Overflow
ts(36,23): error TS2304: Cannot find name 'MessageEvent'. does anyone know why this is happening? this is my package.json file: { "name": " ...
Read more >MessageEvent - Web APIs - MDN Web Docs - Mozilla
The MessageEvent interface represents a message received by a target object. This is used to represent messages in:.
Read more >message event - Slack API
A message is delivered from several sources: They are sent via the Real Time Messaging API when a message is sent to a...
Read more >Activiti User Guide
The source code of Activiti can be found on https://github.com/Activiti/ ... name are internal implementation classes and cannot be considered stable.
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
Thanks @bennyn for your quick response.
Ideally, “reconnecting-websocket” would use “@types/ws” which has a definition for
WebSocket.MessageEvent
:https://github.com/DefinitelyTyped/DefinitelyTyped/blob/47e9cf6d8947e46a82bb09bbcc3dd74a3ac0ffa1/types/ws/index.d.ts#L188-L192
Unfortunately, “reconnecting-websocket” currently relies on the “dom” lib that ships with TypeScript. That’s why you would have to write your own definition for
MessageEvent
if you like to use it with React Native.Example: