简体   繁体   English

如何修复“TypeError:System.config 不是函数”

[英]How to fix ''TypeError: System.config is not a function'

I am learning TypeScript and today I installed SystemJS so that I could import some files.我正在学习 TypeScript,今天我安装了 SystemJS,以便我可以导入一些文件。 First I only imported the main file that needed being run ie app.js, in index.html首先我只在 index.html 中导入了需要运行的主文件,即 app.js

<script src="node_modules/systemjs/dist/system.js"></script>
<script>
     System.import('app.js');
</script>

But I got this error: https://i.stack.imgur.com/lz7Hm.png但是我收到了这个错误: https ://i.stack.imgur.com/lz7Hm.png

So I turned my html code into this:所以我把我的html代码变成了这个:

<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.stack.imgur.com/RS0k7.png现在我收到这个错误: https ://i.stack.imgur.com/RS0k7.png

package.json:包.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") 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我猜你会错误地升级到最新的 system.js ...... SystemJS 2.0 不支持 System.Config 参考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它是使用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.找到system.js并将System.config()放入其中,这将修复错误。

<script src="node_modules/systemjs/dist/system.js">
        System.config({
        baseURL: "/",
        packages: {
          "/": {
            defaultJSExtensions: true
          }
        }
      })
      System.import("app.js")</script>
<script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM