简体   繁体   中英

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?

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();

Just a couple more ways you can do it.

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

or

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM