emailjs/emailjs-tcp-socket

Forge is not defined - require on nwjs 0.13 beta2

AndryBray opened this issue · 11 comments

Hello,
trying to require wo-smtpclient on nwjs 0.13 beta2 I get this error:

Uncaught /build/node_modules/wo-smtpclient/node_modules/tcp-socket/src/tcp-socket-tls.js:30  
message: "forge is not defined"

I found a workaround setting process.versions.electron = 'fake-electron-app' before to call require('wo-smtpclient')

I'm thinking if this is related to the beta stage of nwjs (which one is under development).

any news on this? are you sure this is still the problem?

It's still there. I believe tcp-socket-tls.js:30 should be

    module.exports = factory(require('node-forge'));

although line 29 talks about "fallback to forge browser global"

can you please debug why it would even require the tls helper (tcp-socket-tls)? that should not even happen. i wonder why it doesn't take the correct route to require the native net and tls...

I'm not running electron but chrome apps, so it takes this route as it should. tcp-socket-tls has to be required, even though it isn't used, since _useForgeTls is set in a callback.

what version of electron are you using? can you please figure out why process.versions.electron doesn't work?

Not electron, but Chrome Apps. @AndryBray is running NW.js 0.13 which "supports Chrome App".

sorry, i misread that.
the docs are not terribly useful here and searching the codebase didn't yield anything immediately useful, either.
i assume that nw.js will just magically emulate the proprietary chrome platform api? i don't really know what "supports chrome app" is even supposed to mean...

but still, there are ways for you to identify node-webkit. one of them is process.versions.nw, or the older process.versions['node-webkit']. can you guys please confirm that?
or is that process.versions property somehow unset when running a chrome app?

I think it's more than emulating, pretty sure they use the Chromium code base to implement it. It also has Node.js APIs, but I don't use NW.js and don't know which code path is better.

My first comment is a fix for this issue as described in the title. Forge is an undefined global variable and should rather be required using the same name as the dependency in package.json, node-forge.

But I understand that it's not pleasant to pull in this 2.5mb dependency if not needed. Perhaps the global should then be referred to as window.forge? That fixes "Uncaught ReferenceError: forge is not defined".

ok, but that's a whole other discussion, maybe open a separate issue for that.

we still need to find out how to make this module aware of nwjs so it can work with the native tcp socket. forge should only be used when absolutely necessary, see digitalbazaar/forge#217

one question: do you browserify your sources even though they run locally in nw.js? that would explain why the UMD header is not able to detect nw.js via process.versions