Skip to content Skip to sidebar Skip to footer

Difference Between Import And Import From

I'm looking through some ES6/browserify tutorials and I see something like: import 'jquery'; import domready from 'domready'; What is the difference between import and import from

Solution 1:

Your first line

import'jquery';
// is functionally equivalent torequire('jquery');

Your second line

import domready from'domready';
// is technically equivalent tovar domready = require('domready');

So you can probably see why the second one is the only one that works for you.

Solution 2:

Please have a look at- mozilla reference for import

Posting as answer because I do not have enough reputation to make a comment. Hope it helps.

Solution 3:

The reason jQuery still works is because of what jquery does. If you look at the source of the jquery library, it sets itself as window.jQuery. This creates the jQuery and $ variables in the global scope, so you can still use the variables jQuery and $. the domready library does not. It returns an instance of itself, so you have to save that to a variable using import from.

Post a Comment for "Difference Between Import And Import From"