1

I've got an Angular 2 project and have been using debug with no problems. I'm now trying to use rollup and I get the error:

Cannot call a namespace ('debugModule')

This refers to the way I import debug:

import * as debugModule from 'debug';

I've seen that the solution to this is to import without using the * as someName syntax, like this:

import debug from 'debug';

or maybe:

import { Debug } from 'debug';

...but neither of those work (has no default export and has no exported member 'Debug'). I've done my best to look at the source of both debug and @types/debug to see what I should import, but all I can see is from @types/debug - there are IDebug and IDebugger interfaces which aren't what I'm looking for.

How should I be importing debug such that rollup will be OK with it?

It looks like I can coerce it into working by calling it this way:

debug = debugModule.call(this, 'module:component');

Although I'm not sure what repercussions that might have going forward...

WillyC
  • 3,917
  • 6
  • 35
  • 50

2 Answers2

0

So I don't know why, but if you have installed @types/debug then import debug from 'debug' won't work, but if you just remove @types/debug then you can import it. This doesn't solve all the problems I have with debug when using rollup, but it stops the Cannot call namespace problem and you can call debug normally.

WillyC
  • 3,917
  • 6
  • 35
  • 50
0

You can import it as follows

import * as debugModule from 'debug';
const debug = debugModule()
Koray Güclü
  • 2,857
  • 1
  • 34
  • 30