martynsmith / node-irc

NodeJS IRC client library
GNU General Public License v3.0
1.33k stars 424 forks source link

Module not found: Error: Can't resolve '../build/Debug/iconv.node' in '....\angular-electron\node_modules\irc\node_modules\iconv\lib' (webpack?) #531

Open Booster2ooo opened 6 years ago

Booster2ooo commented 6 years ago

Hello, I came across a weird behavior with irc module, iconv and webpack. When simply using irc module with nodejs, I've got no problem so far. But, if I try to use it in an Angular5 Electron app, webpack fails to compile:

ERROR in ./node_modules/irc/node_modules/iconv/lib/iconv.js
Module not found: Error: Can't resolve '../build/Debug/iconv.node' in '...\angular-electron\node_modules\irc\node_modules\iconv\lib'

webpack: Failed to compile.

I had a look, the iconv.node is present (in Release/), i tried to recompile iconv with differents params but still got the error.

So, I tracked the error down to those lines:

Client.prototype.convertEncoding = function(str) {
    var self = this, out = str;

    if (self.opt.encoding) {
        try {
            var charsetDetector = require('node-icu-charset-detector');
            var Iconv = require('iconv').Iconv;
            var charset = charsetDetector.detectCharset(str);
            var converter = new Iconv(charset.toString(), self.opt.encoding);

            out = converter.convert(str);
        } catch (err) {
            if (self.opt.debug) {
                util.log('\u001b[01;31mERROR: ' + err + '\u001b[0m');
                util.inspect({ str: str, charset: charset });
            }
        }
    }

    return out;
};

If I comment the try/catch part, webpack compiles with no error:

Client.prototype.convertEncoding = function(str) {
    var self = this, out = str;

    if (self.opt.encoding) {
        // try {
            // var charsetDetector = require('node-icu-charset-detector');
            // var Iconv = require('iconv').Iconv;
            // var charset = charsetDetector.detectCharset(str);
            // var converter = new Iconv(charset.toString(), self.opt.encoding);

            // out = converter.convert(str);
        // } catch (err) {
            if (self.opt.debug) {
                util.log('\u001b[01;31mERROR: ' + err + '\u001b[0m');
                util.inspect({ str: str, charset: charset });
            }
        //}
    }

    return out;
};

Env: Win 10 x64 node v8.9.4 x64 npm v5.6.0 node-gyp v3.6.2 irc 0.5.2 electron 1.8.2 angular/cli: 1.7.1 ngtools/webpack: 1.10.1

matt1 commented 5 years ago

Same issue here, also on Win10x64

cbartondock commented 4 years ago

Exact same issue in 2020. What the heck?

Booster2ooo commented 4 years ago

The project isn't maintained anymore I'm afraid.

There are some forks that might be a better options for now, like https://www.npmjs.com/package/funsocietyirc-client https://www.npmjs.com/package/irc-upd

Or an alternative https://github.com/kiwiirc/irc-framework