Errors / JavaScript errors
Uncaught SyntaxError: Cannot use import statement outside a module
A modern script was loaded the old way, so the browser refused to read it.
The whole file is skipped.
Why it happens
- A file using
importloaded with<script src>instead of<script type="module" src>. - A library's ESM build linked directly where its browser (UMD) build was meant.
How to fix it
- Add
type="module"to the script tag (it then runs deferred, and in its own scope). - Or bundle the code so the browser gets one plain script.
- Or use the library's UMD build, which does not use
import. - To confirm, open the file named on the console line in DevTools' Sources panel: an
importon its first lines, loaded by a tag with notype, is this error. The same code under a bundler's dev server works, which is why it often appears only after a hand-made deploy or a copied snippet.
Whose problem it is
Usually the site's own code or settings.
Does your site have it?
Free, no account. We open your page and four more in a clean Chrome and list every error like this one, with the page and the click that caused it. How the free page check works.
Often seen with
- require is not definedA file written for a server's module system was sent to the browser as it is.