clemos / haxe-js-kit

Haxe tools and externs for Javascript and Node.js
MIT License
128 stars 42 forks source link

SocketIO clientside error "Uncaught ReferenceError: process is not defined" #141

Closed MatthijsKamstra closed 8 years ago

MatthijsKamstra commented 8 years ago

I am currently working on making a socketio example. I use https://github.com/clemos/haxe-js-kit/blob/develop/test/SocketIoTest.hx as a reverence

And I ran into a bug on the client:

client.js:2 Uncaught ReferenceError: process is not defined

Played around with it and I can stop that error when I remove js-kit

-lib js-kit

Source will be generated

// Generated by Haxe 3.3.0
(function () { "use strict";
...

instead off

// Generated by Haxe 3.3.0
if (process.version < "v4.0.0") console.warn("Module " + (typeof(module) == "undefined" ? "" : module.filename) + " requires node.js version 4.0.0 or higher");
(function () { "use strict";
...

So I guess you do some macro magic (yes I still call it magic) and checks for Node/Node-version, which is not necessary on the client. So perhaps first a check for process

if (typeof process !== 'undefined' ) if (process.version < "v4.0.0") console.warn("Module " + (typeof(module) == "undefined" ? "" : module.filename) + " requires node.js version 4.0.0 or higher");
MatthijsKamstra commented 8 years ago

maybe this is more complicated then I first thought...

-lib hxnodejs

adds also the process code

But not sure where I should send this bug...

https://github.com/HaxeFoundation/hxnodejs or even https://github.com/HaxeFoundation/haxe/

Lets see if I can call upon the allmighty @nadako :D

nadako commented 8 years ago

You can add -D hxnodejs_no_version_warning to disable this.

Checking for process probably makes sense, but i'm not sure how/why do you use hxnodejs API without node?

clemos commented 8 years ago

It's due to haxe-js-kit depending on hxnodejs, even though it's not server/nodejs only.

More generally, I wonder if it wouldn't be better to let the user -D nodejs if he wants to. One may want to create cross-platform haxelib (browser js / nodejs), but there's no way to make it depend on hxnodejs without all the -D and extraParams.

I'm really not sure, though.

clemos commented 8 years ago

In this particular case, socket.io's interface is really similar in node and in the browser, so it share a couple of interfaces.

clemos commented 8 years ago

All in all, I think checking for process in hxnodejs is fine.

MatthijsKamstra commented 8 years ago

Thx heroes of Haxe! Especially for the quick responds...

@nadako

@clemos

clemos commented 8 years ago

Thanks for your great tutorials @MatthijsKamstra :D

MatthijsKamstra commented 8 years ago

done: http://matthijskamstra.github.io/haxenode/12socket/example.html

nadako commented 8 years ago

do you want me to make an issue at hxnodejs?

you could even do a PR for this https://github.com/HaxeFoundation/hxnodejs/blob/master/src/_hxnodejs/version-warning.js