如何修復錯誤 \"unexpected token \"{\". import call expects exactly one argument\"

以下是修復 “SyntaxError: Unexpected token ‘{’. import call expects exactly one argument.” 錯誤的方法: 我在 Safari 中遇到了這個問題。在 Chrome 中,相同的問題顯示為 “Uncaught SyntaxError: Cannot use import statement outside a module”,但原因是一樣的。 我試圖加載一個使用 ES 模塊風格的腳本,當我注意到腳本沒有加載時,並且在瀏覽器控制台中出現了這個錯誤: "SyntaxError: Unexpected token '{'. import call expects exactly one argument." 修復這個問題的方法很簡單,只需要將 <script src="./file.js"></script> 替換為 <script type="module" src="./file.js"></script> 即可。