I read a lot about module and thought that i really understand it. But later i had a simple example with two java script files: 1.js file:
import './2.js';
console.log('importing');
2.js:
console.log('exporting module');
const a = 10
export const b = [];
and it the html file it was declared:
<defer src="1.js">
Then when running the code i got the following Error:
uncaught syntax Error: Cannot use import statement outside of a module
Now i'm trying to understand, if i added a type="module" to the above brackets, is it the thing which make the 1.js to be a module?!? If the answer is yes, so what make 2.js a module and not just a script?
In addition does importing this way:
import './2.js'
will import the const b from 2.js or not? i know that it will print to console but i can't understand if const b will be imported or not and from an unclear reason when running the code in my browser i'm getting two erros: 1.Access to script at 'file:///C:/Users/Dor/Desktop/17-Modern-JS-Modules-Tooling/starter/script.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.
2.GET file:///C:/Users/Dor/Desktop/17-Modern-JS-Modules-Tooling/starter/script.js net::ERR_FAILED