Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: WebSocket is not defined #33

Open
CrazyFlasher opened this issue Sep 10, 2021 · 3 comments
Open

ReferenceError: WebSocket is not defined #33

CrazyFlasher opened this issue Sep 10, 2021 · 3 comments

Comments

@CrazyFlasher
Copy link

What I've missed?
Code

import hx.ws.WebSocket;

class Ws
{
    static public function main()
    {
        var ws:WebSocket = new WebSocket("ws://127.0.0.1:3001");
    }
}

Build

haxe -js client.js -main Ws -debug -cp src -lib hxWebSockets

Run

node client.js

Error

ReferenceError: WebSocket is not defined
    at hx_ws_WebSocket.open (C:\work\projects\domwires-devkit-hx\client.js:386:18)
    at new hx_ws_WebSocket (C:\work\projects\domwires-devkit-hx\client.js:376:8)
    at Function.Ws.main (C:\work\projects\domwires-devkit-hx\client.js:75:11)
    at C:\work\projects\domwires-devkit-hx\client.js:673:4
    at Object.<anonymous> (C:\work\projects\domwires-devkit-hx\client.js:674:3)
←[90m    at Module._compile (internal/modules/cjs/loader.js:1063:30)←[39m
←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:928:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:769:14)←[39m
←[90m    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)←[39m
```
@CrazyFlasher
Copy link
Author

Adding this line resolved the issue:

        #if js
        untyped global.WebSocket = require("ws");
        #end

@ianharrigan
Copy link
Owner

Is this when running it within node?

@ianharrigan ianharrigan reopened this Sep 13, 2021
@CrazyFlasher
Copy link
Author

Yes. I run it on NodeJS for unit testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants