AI Workshop: learn to build apps with AI →
ES Modules: How to fix the error "unexpected token "{". import call expects exactly one argument"

Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.


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>

Lessons in this unit:

0: Introduction
1: How to fix "cannot use import statement outside a module"
2: How to fix "__dirname is not defined in ES module scope"
3: ▶︎ How to fix the error "unexpected token "{". import call expects exactly one argument"
4: How to enable ES Modules in Node.js
5: How to use .env files in Node.js with import syntax
6: How to use import in Node.js
7: Expose functionality from a Node file using exports