electron-userland / electron-compilers

DEPRECATED: Compiler implementations for electron-compile
35 stars 55 forks source link

Incorrect default import/export #86

Closed justintaddei closed 6 years ago

justintaddei commented 6 years ago

Not sure if this is a bug or if I'm doing something wrong here.

The ws module exports WebSocket like so:

// `ws` module
module.exports = WebSocket;

I'm importing WebSocket from the ws module like so:

// server.ts
import 'WebSocket' from 'ws';

const Server  = new WebSocket.Server(options);

Seems fine, right? Well, it is being compiled to the following:

var ws_1 = require("ws");

var Server = new ws_1.default.Server(options);

The problem is that ws_1.default is undefined. It should be compiled to ws_1.Server, should it not?

MarshallOfSound commented 6 years ago

should it not?

This is how typescript works, when you do import foo from 'bar' it expects to import the default export from bar and name it foo. Because ws doesn't have a default export it will fail.

You should be using import * as WebSocket from 'ws'

See https://www.typescriptlang.org/docs/handbook/modules.html for more info