Can I use import and export directly?

suppose there are only a.js and b.js (only two js and nothing else)

b.js export A variable is used for a.js

can you directly use import and export without using packaging and compilation tools such as webpack or babel

can it be achieved with the help of a browser? can node 8.9.3 report errors with the latest version of node

Feb.26,2021

Yes, this is the syntax of es6, but it is different to write it in the script definition type. I have seen the explanation that others have written that they have not used
mdn:
https://developer.mozilla.org.


1.node 8.9.3 supports

node-- experimental-modules a.mjs

2. Browser does not support


the latest chrome support


The

browser loads the ES6 module and also uses the < script > tag, but adds the type= "module" attribute.

< script type= "module" src= "foo.js" > < / script >


load es6 module in node module:
Node requires ES6 module to use .mjs suffix file name. That is, as long as the import or export commands are used in the script file, the suffix name .mjs must be used.


all the above is true, but one problem is ignored. Browser files protocol cannot cross-domain, that is to say, import can only be used if there is a server locally.

Menu