I need all simple and in the same folder... These two scripts are running with node --experimental-modules test.mjs
, working fine:
test.mjs
:
import myClass from './myClass.mjs';
const x = new myClass()
console.log(x.test)
myClass.mjs
:
'use strict';
export default class MyClass { ... etc. ...}
But when using with browser, there are erros:
index.htm
<!DOCTYPE html>
<html>
<head>
<script src="./myClass.mjs"></script>
<script>
const x = new myClass()
console.log(x.test)
</script>
</head>
<body> <p>My test page</p> </body> </html>
ERRORS:
- SyntaxError: Unexpected token export
- Uncaught ReferenceError: myClass is not defined
See also
Localhost not loading module complementar question.