The browser does not support es Module, so it needs label or webpack to use it

// Test: module A, need to import module B
Copy the code
  • Loading module A
    <script src="./a.js" type="module"></script>
    // The module identifier is required for the browser to recognize the import
Copy the code
  • Import B from module A
/ / test 1
import {b} from './b.js'
console.log(b)

/ / test 2
setTimeout(() = > {
    import('./b.js').then(res= > {
        console.log('res',res)
    })   
}, 5000);
Copy the code
  • complete