I want to call my function main() using html onload event and console.log text imported from another (generateObject.js) file, but when I import function, onload event stop working and function main() is not anymore used.
html:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="main.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body onload="main()">
</body>
</html>
generateObject.js:
export function hello() {
return "Hello";
}
main.js:
import { hello } from './generateObject.js';
function main(){
console.log(hello());
}
main();
When I try console.log("text") in main() it works but when I try to use imported function it's not.
What should I do to fix that?
Errors in Chrome console:
Uncaught SyntaxError: Cannot use import statement outside a module (main.js:1)
index.html:8 Uncaught ReferenceError: main is not defined at onload (index.html:8)