Open igoventura opened 6 years ago
sounds like we're sittin in the same boat #168
Are you sure that the node net
and tls
APIs are available in your electron app where you're trying to invoke this?
The error seems to be caused by:
var _tls = __webpack_require__("./node_modules/node-libs-browser/mock/empty.js");
var _tls2 = _interopRequireDefault(_tls);
...
this._socket = this.ssl ? _tls2.default.connect(this.port, this.host, {}, function () {
return _this._emit('open');
}) : _net2.default.connect(this.port, this.host, function () {
return _this._emit('open');
});
Because the error message is _tls2.default.connect is not a function
.
Ooooh, I think I see what the problem is...
Here is the import for net
and tls
respectively. The way babel is polyfilling it is by checking whether it's a babel-transpiled module, i.e. whether it has a property called __esModule
. Mixing imports for ES6 and commonjs modules is actually illegal in the ECMAScript standard. Roughly speaking: import
is for ES6 modules and require
for commonjs modules, since the two have different runtime behaviors.
Can you do me a favor and put a breakpoint in line 53 of node-socket.js in the tcp-socket shim and see what the object looks like? after require
, net
and tls
should not have the __esModule
property set. If the property is missing, it should behave correctly, as babel polyfills it. if the property is there, that's the source of the error.
I just pushed a change where the tcp-socket integration test does not babelify on the fly and uses the transpiled pre-built sources just as any other project would consume the lib. The weird thing is: It runs fine.
https://github.com/emailjs/emailjs-tcp-socket/commit/a6600f063b4f36063446a44c8337c61aead0ae02
Here's the test... https://github.com/emailjs/emailjs-tcp-socket/blob/master/test/node/node-integration.js
Is your repo open so that I could check out where it breaks for you? This sucks and I can't seem to reproduce it...
And one more thing: AFAIK in electron, net
and tls
needs to be run on the node side of things (in main), not from the renderer process. However, it's been a while since I've played with electron, so this might have changed.
It's just a test project so i don't have put into an repo. I'll test with the breakpoint you mentioned and comment the result. Also, I'll put the project in one repo and share it here.
any news on this?
any updates for this issue? "Could not connect to server TypeError: _net2.default.connect is not a function"
@igoventura i assume that means the issue was resolved?
@sujidivakar any news on your end? seems list @igoventura dropped out
ping?
Since nobody bothered to respond, i am closing this ticket for now.
I am having this error when trying to do a progressive web app that runs on browser. Does this lib support this?
I see why this might be confusing. The web stack traditionally does not have a concept of raw sockets. So you can't just drop the library into the browser. Does not work.
However, what you might wanna look into is run a proxy that allows opening a WebSockets-TCP proxy. The emailjs stack was built to support this. Please know that this needs a lot of discussion as it might open up your proxy to a lot of abuse. You can find out more about a TCP proxy here: https://github.com/emailjs/emailjs-tcp-proxy
@felixhammerl I'm now running the proxy on my localhost for testing, but I was unable to find how tell the application to used it. Initially I thought that options of imap-client would accept the ws: {}
key, but look that this is not the way. Can you help me?
You are on the right track. On the one hand, you have to run the proxy so that it can open TCP connection on your behalf, and then you need to connect to the proxy as well. Check the documentation here for how to do it: https://github.com/emailjs/emailjs-tcp-socket#web-sockets
It is actually as simple as telling where to find your socket.io instance and you're good to go :)
If you receive any errors down the road, but see that the general connection starts, it might be TLS certificate errors. What out for that, as the error is a bit tricky and unfortunately get thrown out of band :(
@felixhammerl , I think I am missing something.
I have cloned emaijs-tcp-proxy and ran on my localhost:
PROXY_PORT=9000 npm start
On my code I start the socket with the example code:
var socket = TCPSocket.open('127.0.0.1', 9000, {
ws: {
url: 'http://localhost:8889',
options: {
upgrade: false
}
}
})
Looks like I am missing on how to start the service on port 8889.
Another thing I do not know how to do is how to use the started tcpsocket with ImapClient.
Here you go: https://github.com/emailjs/emailjs-tcp-proxy#usage-as-standalone
> git clone git@github.com:emailjs/emailjs-tcp-proxy.git
> cd emailjs-tcp-proxy
> PROXY_PORT=8889 npm start
That should get you started. Run it on the port you're pointing the TCPSocket
instance to, in this case 8889
:)
If you're serving your app from an express instance already, you can also just hook the proxy into your express instance: https://github.com/emailjs/emailjs-tcp-proxy#usage-as-standalone
I made this, only used port 9000 but the code I pasted above still gives me the error:
_net2.default.connect is not a function
damn. i will look into it.
@felixhammerl ... I do not know if I am missing something or if this is a bug. I am only using emailjs on ionic running on browser served by the ionic serve
command and the emailjs-tcp-proxy on localhost as instructed, nothing more! You mentioned express, I am not using it.
im using ionic as well. Tried the combination of tcp-proxy + tcpClient and i get the _net2.default.connect is not a function as well. Let me know if i can do more helpful stuff than just reading this feed... ;)
hello, I have installed the library on a vue.js app and I get the same error.
I'm just importing the library from a component using
import ImapClient from 'emailjs-imap-client'
and then after initializing the client using
var client = new ImapClient(....
I get the error
TypeError: _tls2.default.connect is not a function
at new TCPSocket
How can I solve it ? thanks (Thomas)
I'm trying to use this in my angular+electron app and getting this error:
[DEBUG][2018-02-09T16:53:31.517Z][1][igoventura@outlook.com][imap-mail.outlook.com] Connecting to imap-mail.outlook.com : 993 polyfills.bundle.js:3186 [DEBUG][2018-02-09T16:53:31.521Z][1][igoventura@outlook.com][imap-mail.outlook.com] Entering state: 1 polyfills.bundle.js:3186 [ERROR][2018-02-09T16:53:31.534Z][1][igoventura@outlook.com][imap-mail.outlook.com] Could not connect to server TypeError: _tls2.default.connect is not a function webpackJsonp../node_modules/zone.js/dist/zone-mix.js.ZoneDelegate.invoke @ polyfills.bundle.js:3186 webpackJsonp../node_modules/zone.js/dist/zone-mix.js.Zone.run @ polyfills.bundle.js:2936 console.(anonymous function) @ polyfills.bundle.js:5867 log @ vendor.bundle.js:98237 error @ vendor.bundle.js:98245 error @ vendor.bundle.js:96366 (anonymous) @ vendor.bundle.js:95481 step @ vendor.bundle.js:95368 (anonymous) @ vendor.bundle.js:95368 webpackJsonp../node_modules/zone.js/dist/zone-mix.js.ZoneDelegate.invoke @ polyfills.bundle.js:3186 onInvoke @ vendor.bundle.js:49849 webpackJsonp../node_modules/zone.js/dist/zone-mix.js.ZoneDelegate.invoke @ polyfills.bundle.js:3185 webpackJsonp../node_modules/zone.js/dist/zone-mix.js.Zone.run @ polyfills.bundle.js:2936 (anonymous) @ polyfills.bundle.js:3638 webpackJsonp../node_modules/zone.js/dist/zone-mix.js.ZoneDelegate.invokeTask @ polyfills.bundle.js:3219 onInvokeTask @ vendor.bundle.js:49840 webpackJsonp../node_modules/zone.js/dist/zone-mix.js.ZoneDelegate.invokeTask @ polyfills.bundle.js:3218 webpackJsonp../node_modules/zone.js/dist/zone-mix.js.Zone.runTask @ polyfills.bundle.js:2986 drainMicroTaskQueue @ polyfills.bundle.js:3396 polyfills.bundle.js:3186 [DEBUG][2018-02-09T16:53:31.536Z][1][igoventura@outlook.com][imap-mail.outlook.com] Entering state: 5 polyfills.bundle.js:3186 [DEBUG][2018-02-09T16:53:31.537Z][1][igoventura@outlook.com][imap-mail.outlook.com] Closing connection... polyfills.bundle.js:5864 ERROR Error: Uncaught (in promise): TypeError: _tls2.default.connect is not a function TypeError: _tls2.default.connect is not a function at new TCPSocket (vendor.bundle.js:100809) at Function.open (vendor.bundle.js:100785) at Promise (vendor.bundle.js:97414) at new ZoneAwarePromise (polyfills.bundle.js:3655) at Imap.connect (vendor.bundle.js:97413) at Promise (vendor.bundle.js:95493) at new ZoneAwarePromise (polyfills.bundle.js:3655) at Client._openConnection (vendor.bundle.js:95489) at vendor.bundle.js:95466 at Generator.next (<anonymous>) at new TCPSocket (vendor.bundle.js:100809) at Function.open (vendor.bundle.js:100785) at Promise (vendor.bundle.js:97414) at new ZoneAwarePromise (polyfills.bundle.js:3655) at Imap.connect (vendor.bundle.js:97413) at Promise (vendor.bundle.js:95493) at new ZoneAwarePromise (polyfills.bundle.js:3655) at Client._openConnection (vendor.bundle.js:95489) at vendor.bundle.js:95466 at Generator.next (<anonymous>) at resolvePromise (polyfills.bundle.js:3589) at resolvePromise (polyfills.bundle.js:3560) at polyfills.bundle.js:3638 at ZoneDelegate.webpackJsonp../node_modules/zone.js/dist/zone-mix.js.ZoneDelegate.invokeTask (polyfills.bundle.js:3219) at Object.onInvokeTask (vendor.bundle.js:49840) at ZoneDelegate.webpackJsonp../node_modules/zone.js/dist/zone-mix.js.ZoneDelegate.invokeTask (polyfills.bundle.js:3218) at Zone.webpackJsonp../node_modules/zone.js/dist/zone-mix.js.Zone.runTask (polyfills.bundle.js:2986) at drainMicroTaskQueue (polyfills.bundle.js:3396) at <anonymous>