node-libquassel icon indicating copy to clipboard operation
node-libquassel copied to clipboard

Does not work when running from node

Open Ketchup901 opened this issue 6 years ago • 0 comments

In the readme, you have given this example:

const { Client } = require('libquassel');
const net = require('net');

const socket = net.createConnection({
  host: "localhost",
  port: 4242
});

const quassel = new Client((next) => next("user", "password"));

quassel.on('network.init', (networkId) => {
    network = quassel.networks.get(networkId);
    // ...
});

// ...

quassel.connect(socket);

However, when you run this example using node foo.js, there is an error saying:

import './usertypes'; // register usertypes first
^^^^^^

SyntaxError: Cannot use import statement outside a module

If you change const { Client } = require('libquassel'); to const { Client } = require('libquassel/dist/libquassel');, the error is:

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.libquassel=t():e.libquassel=t()}(window,function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=functi

ReferenceError: window is not defined

If you add global.window = {}; to the beginning of the file, the script seems to run, but it closes after a tenth of a second.

Ketchup901 avatar Nov 23 '19 18:11 Ketchup901