I am learning TypeScript and today I installed SystemJS so that I could import some files. First I only imported the main file that needed being run i.e. app.js, in index.html
<script src="node_modules/systemjs/dist/system.js"></script>
<script>
System.import('app.js');
</script>
But I got this error: https://i.sstatic.net/lz7Hm.png
So I turned my html code into this:
<script src="node_modules/systemjs/dist/system.js"></script>
<script>
System.config({
baseURL: '/',
packages: {
"/ts": {
defaultExtension: 'js'
}
}
});
System.import('app.js');
</script>
Now I am getting this error: https://i.sstatic.net/RS0k7.png
package.json:
{
"name": "ts",
"version": "1.0.0",
"description": "",
"main": "app.js",
"dependencies": {
"jquery": "^3.4.0",
"systemjs": "^3.1.2",
"typescript": "^3.4.2"
},
"devDependencies": {
"lite-server": "^2.4.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "lite-server"
},
"author": "",
"license": "ISC"
}
app.ts: console.log("Hello")
I am stuck at this point. Any help would be appreciated. Thanks in advance.
I guess you would have upgraded to the latest system.js by mistake... SystemJS 2.0 does not support System.Config Refer to https://guybedford.com/systemjs-2.0
It is instead done using https://github.com/systemjs/systemjs/blob/2.0.0/docs/package-name-maps.md
If you managed to update the code by now, might as well post the updated sample here for use of everyone.
Locate system.js and put System.config() inside it, this would fix the error.
<script src="node_modules/systemjs/dist/system.js">
System.config({
baseURL: "/",
packages: {
"/": {
defaultJSExtensions: true
}
}
})
System.import("app.js")</script>
<script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With