JavaScript Error Handling 1

JavaScript Error Handling 1

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

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.