How can I use an external library in my project?

I’m trying to use noisejs as a node.js module. I’ve modified webpack.common.js to import node modules:

“lib”: path.resolve (__dirname, “node_modules”)

I try to import the library like this

import Noise from ‘lib/noisejs’;

var noise = new Noise(Math.random());

But this code returns an error:

Uncaught TypeError: _noisejs2.default is not a constructor

How can I fix it?

It looks like the library exports Noise directly (rather than having a default export as is expected by ES6) so you might be able to do it more like this?

import * as Noise from 'lib/noisejs';
1 Like