emailjs/emailjs-tcp-socket

Build with webpack fails

BHSPitMonkey opened this issue · 6 comments

I've installed tcp-socket via npm, and when I add

import TCPSocket from 'tcp-socket';

to my project, my webpack build fails with

ERROR in ./~/tcp-socket/src/tcp-socket.js
Module not found: Error: Cannot resolve module 'tcp-socket-tls' in /home/myuser/myproject/node_modules/tcp-socket/src
 @ ./~/tcp-socket/src/tcp-socket.js 26:8-65

It seems that it's falling into the first if clause in tcp-socket.js:

    if (typeof define === 'function' && define.amd) {
        // amd
        define(['tcp-socket-tls'], factory.bind(null, navigator));
    }

when it seems that the module.exports behavior later on is what we want. Any ideas?

webpack supports both AMD and CommonJS style modules which the code doesn't take into account. You can use this webpack loader, https://github.com/webpack/imports-loader#disable-amd, to fix the issue.

i assume this can be closed?

Sorry, didn't see the notification from before.

I would argue that nifgraup's workaround isn't a good excuse to not fix this (since the problem is in tcp-socket.js). That said, I ended up going with my own implementation, so I'm not waiting on a fix or anything.

wanna submit this as a PR? you obviously know the issue better than me :)

Hi, I created some example to show how emailjs packages works with webpack:
https://github.com/Axel186/emailjs-and-webpack-example

Take a look - hope it will be useful!

thanks @Axel186 :)