How to Resolve the Error “unexpected token “{“. import call expects exactly one argument”
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:
1 | SyntaxError: Unexpected token '{'. import call expects exactly one argument. |
To rectify this error, I employed the following solution: Instead of using
1 | <script src="./file.js"></script> |
I replaced it with
1 | <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.