Been trying to import external modules in function node , while many were successful some are giving "TypeError: xxxx is not a constructor"

const { DSLink } = 'dslink/js/web';

async function main() {
    let link = new DSLink('ws://localhost:8080/ws', 'json');

    let { requester } = link;

    console.log(await requester.subscribeOnce('/sys/dataOutPerSecond'));


return msg;

Any help from experts appreciated

What have you added to the Setup tab?

Your first line of code is definitely incorrect - you are assigning DSLink to be a value of the string "dslink/js/web" - that doesn't have any relation to an actual module.

That code example is for a web browser only.

The function node runs in NodeJS

By sdk-dslink-ts documentation the first line is wrong. Should be: const {DSLink} = require('dslink/js/web'); Pls check that.

The function node runs in nodejs.

The function node does not permit require

that line of code is marked specifically for the browser...

Sure, I missed that :man_facepalming: you're right. @spillz is using the browser and should use the NodeJS example instead.

// const {DSLink} = require("dslink");
const {DSLink} = require("../../js/node");

async function main() {
  let link = new DSLink('testRequester-aa-',
    {isRequester: true},['--broker','http://localhost:8181/dsbroker/conn']
  await link.connect();

  let {requester} = link;

  // list for root node structure once
  console.log((await requester.listOnce('/local/Preference Service/global', 1000)).children);



Well i got this running in node.js

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.