0

I'm currently working on a library (written in TypeScript) for Angular 4.x. The necessary JavaScript bundles are created with Rollup. It all worked fine until I added the big.js library and the corresponding typings (@types/big.js).

I import it like this:

import * as Big from 'big.js';
import BigJS = BigJsLibrary.BigJS;

And use it like this:

// instantiating
let bigValue = Big(value);

// example of parameter usage
private someFunction(value: BigJS) { /* some code */ }

When running Rollup, I now receive the following error: Error: Cannot call a namespace ('Big'). My first thought was to add big.js to the list of externals for Rollup (external: [ 'big.js' ]). This does not solve the problem however.

I could see that the BigJS library has no (default) exports, so I tried using the commonjs and nodeResolve Rollup plugins like this:

  plugins: [
      nodeResolve({
          jsnext: true,
          main: true
      }),
      commonjs({})
  ]

I have a feeling that I'm overseeing something obvious. I'd be thankful if someone could point out the mistake that I'm making here.

Kaj Nelissen
  • 915
  • 10
  • 29

1 Answers1

1

Calling an imported namespace (the * as Big part) is a TypeScript idiom which is incompatible with ES modules. Try doing this instead:

import Big from 'big.js';

You'll still need the node-resolve and commonjs plugins, since Big.js is a CommonJS module.

Rich Harris
  • 28,091
  • 3
  • 84
  • 99