← flaviocopes.com

How to fix the error "unexpected token "{". import call expects exactly one argument"

Published Apr 20 2022

Psssst! The 2023 WEB DEVELOPMENT BOOTCAMP is starting on FEBRUARY 01, 2023! SIGNUPS ARE NOW OPEN to this 10-weeks cohort course. Learn the fundamentals, HTML, CSS, JS, Tailwind, React, Next.js and much more! ✨

Here is how I solved the “SyntaxError: Unexpected token ’{’. import call expects exactly one argument.” error.

I had this problem in Safari. The same problem in Chrome is shown as “Uncaught SyntaxError: Cannot use import statement outside a module”, but the cause is the same.

I was trying to load a script that used ES module style imports, when I noticed the script was not loading, and I had this error in the browser console:

"SyntaxError: Unexpected token '{'. import call expects exactly one argument."

All I had to do to fix this was to use

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

instead of

<script src="./file.js"></script>


I write books for developers 👇🏼

© 2023 Flavio Copes Flavio Copes made in Italy 🇮🇹 using Notion to Site Notion to Site