I've been attempting to implement the module system using Es6 and SystemJs.
This snippet shows my library code:
export function sayHello( name ) {
return `Hello ${name}`;
};
I also import app.js:
import { sayHello } from './lib'
sayHello('Myname');
In tsconfig.json, I have specified the compiler options as follows:
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"module": "commonjs",
"target": "ES5",
"outDir": "built",
"rootDir": "src"
},
"include": [
"**/*"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
My package.json file includes the following dependencies:
{
...
"dependencies": {
"lite-server": "^2.4.0",
"systemjs": "^3.1.1"
}
}
The index.html file is structured like this:
<!DOCTYPE html>
<html>
<head><title>TypeScript Greeter</title></head>
<body>
<script src="/node_modules/systemjs/dist/system.min.js"></script>
<script>
System.import('/built/app.js').then(function(){
console.log('Done');
}, function(error){
console.log(error);
});
</script>
</body>
</html>
However, upon running the code, I encounter the error message:
Uncaught ReferenceError: exports is not defined
Can anyone please guide me on where I might have made an error?