Works like a charm :
declare var require;
const Quassel = require( 'libquassel/lib/libquassel.js' );
console.log( 'Quassel', Quassel );
Looking at the libquassel
's folder in node_module, realised that there is no index.js
in the root directory.
When there is not index.js
, you can't do this :
require( 'libquassel' );
Simply because node doesn't know what to pull in for you, so you'd need to specify the exact path, which is not that bad in this case.
Also , note that it's better to move declare var require;
to your typings file located under the src folder, because you might need to declare it again , so it's better be there.
EDIT :
Here is what I found after trying to instantiate the Quassel like bellow :
const Quassel = require( 'libquassel/lib/libquassel.js' );
console.log( 'Quassel', Quassel );
var quassel = new Quassel( "quassel.domain.tld",
4242,
{ backloglimit : 10 },
function ( next ) {
next( "user", "password" );
} );
console.log( 'quassel', quassel );
And here is my console log :
But having said that, I realised that there is a problem inside the libquassel.js , as bellow :
in line 10, they're doing this :
var net = require('net');
And looking their package.json, there is no such a thing as net
and there is net-browserify-alt
;
So if they change that import to :
var net = require('net-browserify-alt'),
Everything will work.
Having said that, obviously you don't want to edit your node_module, but I'm really surprised of how this really works even outside of angular and webpack , because clearly they've mentioned a wrong node_module which if you google , there is only one package named net
which I had a look and it's empty and dummy !!!!
** ********** UPDATE : ********** **
What exactly needs to be done :
1- run ng eject
that will generate a webpack.conf.js
inside your root directory.
2- inside that find resolve
property and add :
"alias":{
'net':'net-browserify-alt'
},
so your resolve will probably look like :
"resolve": {
"extensions": [
".ts",
".js"
],
"alias":{
'net':'net-browserify-alt'
},
"modules": [
"./node_modules"
]
},
3- import and use it :
declare var require;
const Quassel = require( 'libquassel/lib/libquassel.js' );
console.log( 'Quassel', Quassel );
var quassel = new Quassel( "quassel.domain.tld",
4242,
{ backloglimit : 10 },
function ( next ) {
next( "user", "password" );
} );
console.log( 'quassel', quassel );
NOTE :
Having a look at webpack configuration, seems like webpack likes to override couple of modules :
"node": {
"fs": "empty",
"global": true,
"crypto": "empty",
"tls": "empty",
"net": "empty",
"process": true,
"module": false,
"clearImmediate": false,
"setImmediate": false
}
I don't exactly know why, but this list is in the webpack config and seems to be making net
to be undefiend ( empty ) and that's why we had to create an alias.