Reputation: 5734
tools.js:
function someFunction() {
console.log(1 + 1);
}
export { someFunction };
main.js
window.onload = function() {
import { someFunction } from 'tools';
};
index.html:
<script src="http://localhost:8080/tools.js" type="module"></script>
<script src="http://localhost:8080/main.js "></script>
And yet I get the error on the subject. What am I doing wrong? Thanks.
Upvotes: 1
Views: 1954
Reputation: 138557
import
s always have to be on the global scope:
import { someFunction } from 'tools.js';
window.onload = function() {
//...
};
Upvotes: 4