how to use import * as Clipboard from 'clipboard' #157

Zhuoqing opened this Issue Jan 5, 2017 · 3 comments


None yet

3 participants

Zhuoqing commented Jan 5, 2017

repro repo is at

The typings for @types/clipboard@1.5.31 is something like

declare class Clipboard {...

declare namespace Clipboard {...

export = Clipboard;
export as namespace Clipboard;

and its usage example is like

import * as Clipboard from 'clipboard';
var cb1 = new Clipboard('.btn');

However when we try to bundle with rollup with same syntax, somehow new Clipboard doesn't work and we had to do new Clipboard.default which doesn't seem right.
#to repro
npm i && npm run build, then load index.html and watch the error in console, can also check jsfiddle here

Note if change to use import Clipboard from 'clipboard'; it works. However in our repo ngc/tsc will complain module has no default export, not sure what magic rollup-plugin-typescript is doing there. Also looks like import Clipboard = require('clipboard'); doesn't work because of es2015 module.

Zhuoqing commented Jan 5, 2017

related to #143
actual in generated bundle file

var clipboard$1 = unwrapExports(clipboard);
var Clipboard = Object.freeze({
	default: clipboard$1,
	__moduleExports: clipboard

while we want it to be
var Clipboard = unwrapExports(clipboard);

@maxisam maxisam referenced this issue in maxisam/ngx-clipboard Jan 5, 2017

Not working with Rollup #22


We have a related issue like rollup/rollup#1267

In Typescript we need to use this import:
import * as $ from 'jquery';

For rollup, the import has to be
import $ from 'jquery';

It looks like there is no way to solve this.
Writing import $ = require('jquery') compiles correctly from typescript for commonjs, but fails when compiling to es2015.


Same here, same problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment