Skip to main content

Command Palette

Search for a command to run...

JavaScript Error Handling 1

"Uncaught SyntaxError: Cannot use import statement outside a module" and "net::ERR_ABORTED 404 (Not Found)"

Updated
•1 min read•View as Markdown
JavaScript Error Handling 1
A

I am a Brand Marketer-turned Frontend Developer.

I was extracting some functions from the Vanilla JavaScript project files for later testing with Jest. I ran into a few errors, so I'm writing this article as a note.

Uncaught SyntaxError: Cannot use import statement outside a module

When I was extracting the functions and importing them in script.js, I got this error. I was able to solve it by adding type="module" to index.html as described here.

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

net::ERR_ABORTED 404 (Not Found)

After that, I got the following error. Following the answer here, I changed import FILENAME from './file' to import FILENAME from './file.js' and the error disappeared.

More from this blog

Aya Takamura

11 posts