Search code examples
javascriptecmascript-6

Add a module in in ES6 using import instead of require


Hi I am trying to add a module to my code. In ES5 I used

var promise = require('bluebird');

So I tried import { promise } from 'bluebird' but it didn't work any idea why?


Solution

  • Actually import { promise } from 'bluebird' translated in es5 as var promise = require('bluebird').promise. So the equivalent of var promise = require('bluebird') in es6 would be import * as promise from 'bluebird'

    EDIT: Based on the comment of @Bergi: import Promise from 'bluebird' is a more simplified version.