I have the following "website" (feel free to skim, the only important part here is the import statement):
<html>
<head>
</head>
<body>
<script>
import * as mathSolverModule from 'components/mathSolverModule';
var result = mathSolverModule.add(2+2);
document.write(result);
</script>
</body>
</html>
The mathSolverModule
file is this:
export function multiply(x, y) {
return x * y;
}
export function add(x, y) {
return x + y;
}
Predictably, I get the following error when running this in latest Chrome:
Uncaught SyntaxError: Unexpected token import
What is the easiest way to fix this? Is there some script I can include to "just make it work" or do I need SystemJS/WebPack/etc and HAVE to compile into something else (ES5, as I understand it)?
Edit, I tried:
<html>
<head>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.14.0/babel.min.js"></script>
</head>
<body>
<script type="text/babel">
import * as mathSolverModule from 'components/mathSolverModule';
var result = mathSolverModule.add(2+2);
document.write(result);
</script>
</body>
</html>
and I get the following:
Uncaught ReferenceError: require is not defined