Search code examples
javascriptes6-module-loader

Having trouble cleanly loading a ES6 module


I am using should() from the chai library.

It works using

var should = require('chai').should();

I'm trying to do it with ES6 modules but can only get it to work this way:

import chai from 'chai';
var should = chai.should();

Is there a cleaning one-liner way to import this module with ES6?


Solution

  • I suggest you read this article about ES6 modules. It explains the difference between default exports and names exports.

    Another suggestion is you can apply all ES6 syntax. Consider to replace var with let or const. It makes your variable scope more reasonable.