Sanchit Goel
Sanchit Goel

Reputation: 141

How to write import statement instead of require statement in Javascript?

I was importing one of the polyfill, "es6-promise" in my jsx file of react application but was not able to import it in a correct way.

I googled N number of solution finally one worked for IE. require('es6-promise').polyfill()

its working fine but, why it was not working for import es6-promise from "es6-promise"; Is there any way to import it first in a variable and then calling the .polyfill() method to that variable?

Upvotes: 0

Views: 61

Answers (2)

nglgzz
nglgzz

Reputation: 46

Just a couple more ways you can do it.

import { polyfill } from 'es6-promise';
polyfill();

or

import ES6Promise from 'es6-promise';
ES6Promise.polyfill();

Upvotes: 0

Amid
Amid

Reputation: 22372

There a multiple ways of how you can import other modules in your code: import

For example:

import * as ES6Promise from 'es6-promise';

ES6Promise.polyfill();

Upvotes: 1

Related Questions