So let's imagine i have two js scripts
script1.js
export default function Hello() {
return "Hello buddy!";
}
script2.js
import { Hello } from './script1.js';
function print(){
let val = Hello;
console.log(val);
}
When i run the function print in browser i get the following error
Uncaught SyntaxError: Cannot use import statement outside a module
Unexpected token 'export'
I did some investigation and this is solved by adding type module to script2.js. But the question is. I dont have a HTML to change the script. I do everything in vanilla javascript. so, is the solution to get the scripts by ID and change the type of the script2.js from text/javascript to module?
Is there any other way to change the script2.js to module?