Telling typescript to to not add ["default'] to new class

Viewed 128

TypeScript code

import ModbusRTU from 'modbus-serial';
var modbus = new ModbusRTU();
modbus.connectTCP("192.168.1.5", { port: 502 });
modbus.setID(1);

setInterval(function() {
    modbus.writeRegister(2048, 2);
}, 100);

transpiles to

"use strict";
exports.__esModule = true;
var modbus_serial_1 = require("modbus-serial");
var modbus = new modbus_serial_1["default"](); //  <-- HERE
modbus.connectTCP("192.168.1.5", { port: 502 });
modbus.setID(1);
setInterval(function () {
    modbus.writeRegister(2048, 2);
}, 100);

However, the code only works without the ["default"] in class instantiation - like so

"use strict";
exports.__esModule = true;
var modbus_serial_1 = require("modbus-serial");
var modbus = new modbus_serial_1(); //  <-- HERE
modbus.connectTCP("192.168.1.5", { port: 502 });
modbus.setID(1);
setInterval(function () {
    modbus.writeRegister(2048, 2);
}, 500);

How to tell the transpiler to nod add it to the code?

1 Answers

In case anyone else is running into this problem. It seems like the exports of this library are a bit faulty. I opened an issue here and a pull request to fix it here.

Edit: My patch was applied to this library, hence this issue should not arise in the future :)

Related