ES module import not working

前端 未结 2 1054
抹茶落季
抹茶落季 2021-01-19 18:19

I am trying to make simple example of vanilla ES import export.

index.js




  

        
2条回答
  •  失恋的感觉
    2021-01-19 18:31

    The simplest would be to remove the export and import expressions since you're already including both files in your html.

    const foo = Math.sqrt(2) // mathModule.js
    console.log(foo) // main.js
    
    
    
      
      
      
    
    
    
    
    

    If you are using node or something similar to run the script, maybe you should use a transpiler such as babel. Import and Export are "new" javascript features hence they're not implemented in most browsers

提交回复
热议问题