In an attempt to answer this question myself, I referred to this answer but ended up getting a similar error.
My current file structure is
-index.html
-imports.js
-script.js
-style.css
In imports.js
, from the question listed earlier, I have
function show() {
console.log('Hello, World!');
}
module.exports = {show}
as a test.
In my index.html
file, I have <script type='module' src='./imports.js'></script>
in order to link to my imports.js
file. And in my scripts.js
file, again as a test, I have
import {show} from "./imports.js";
show();
However, when running this, I get thrown the errors
SyntaxError: Cannot use import statement outside a module
at /script.js:3:1
ReferenceError: module is not defined
at /imports.js:4:2
As my title states, I am trying to import the IO
module, but when I kept getting errors, I went back to test a more basic approach. What am I doing wrong?