If you are facing the error “SyntaxError: Unexpected token ‘{’. import call expects exactly one argument,” this article will guide you through the steps to fix it. Backed by my own experience in resolving this issue, I will provide a solution that has worked for me.

I encountered this error while using Safari, but it may also be displayed as “Uncaught SyntaxError: Cannot use import statement outside a module” in Chrome. However, the root cause remains the same.

The problem occurred when I was attempting to load a script that utilized ES module style imports. Upon inspecting the browser console, I discovered this error message:

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

To rectify this error, I employed the following solution: Instead of using

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

I replaced it with

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

By making this modification, the error was successfully resolved, and the script loaded without any further issues.

Remember to use the corrected code snippet to eliminate the error and ensure the script is loaded correctly.