未定义System.config

时间:2018-10-12 20:09:39

标签: angular systemjs

嗨,我不知道为什么要配置我的角度项目时出现此错误:

System.config is not a funtion

我的package.json和html:

{
  "name": "",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@angular/common": "^5.2.0",
    "@angular/compiler": "^5.2.0",
    "@angular/core": "^5.2.0",
    "@angular/platform-browser": "^5.2.0",
    "@angular/platform-browser-dynamic": "^5.2.0",
    "reflect-metadata": "^0.1.12",
    "rxjs": "^5.5.0",
    "systemjs": "^2.0.2",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@types/core-js": "^2.5.0"
  }
}
<html>
<head>
  <script src="node_modules/zone.js/dist/zone.js"></script>
  <script src="node_modules/reflect-metadata/Reflect.js"></script>
  <script src="node_modules/systemjs/dist/system.js"></script>
  <script>

  System.config({
  // the app will need the following dependencies
  map: {
  '@angular/core': 'node_modules/@angular/core/bundles/core.umd.js',
  '@angular/common': 'node_modules/@angular/common/bundles/common.umd.js',
  '@angular/compiler': 'node_modules/@angular/compiler/bundles/compiler.umd.js',
  '@angular/platform-browser': 'node_modules/@angular/platformbrowser/bundles/platform-browser.umd.js',
  '@angular/platform-browser-dynamic': 'node_modules/@angular/platform-browserdynamic/bundles/platform-browser-dynamic.umd.js',
  'rxjs': 'node_modules/rxjs'
  },
  packages: {
  // we want to import our modules without writing '.js' at the end
  // we declare them as packages and SystemJS will add the extension for us
  '.': {}
  }
  });
  // and to finish, let's boot the app!
  System.import('main');
  </script>
</head>
<body>
  <home>
  Hello
  </home>
</body>
</html>

我认为systemJS的版本是最近的,但我不知道更多。...

SystemJs的配置是否已在最新版本中更改?

3 个答案:

答案 0 :(得分:0)

最新版本的systemjs似乎存在一些问题,您可以将其降级为"0.21.3"版本,然后您会发现一切正常。

在此处结帐angular6-without-cli工作仓库。

  

注意:请确保您先尝试npm install,然后再尝试尝试。

答案 1 :(得分:0)

看来,SystemJS 2的实现方法是将配置(作为有效JSON)放在如下块中:

<script type="systemjs-packagemap">

  {
      "map": {
          "@angular/core": "node_modules/@angular/core/bundles/core.umd.js",
          "@angular/common": "node_modules/@angular/common/bundles/common.umd.js",
          "@angular/compiler": "node_modules/@angular/compiler/bundles/compiler.umd.js",
          "@angular/platform-browser": "node_modules/@angular/platformbrowser/bundles/platform-browser.umd.js",
          "@angular/platform-browser-dynamic": "node_modules/@angular/platform-browserdynamic/bundles/platform-browser-dynamic.umd.js",
          "rxjs": "node_modules/rxjs"
        },
        "packages": {
            "main": "../main.js"
        }
    }
</script>
<script src="node_modules/systemjs/dist/system.js"></script>
<script>
    System.import('main');        
</script>

请注意,必须将其放置在之前 system.js脚本

更多详细信息,请访问their docs

答案 2 :(得分:0)

我想您可能会错误地升级到最新的system.js ...不支持System.Config 请参阅https://guybedford.com/systemjs-2.0

它可以使用https://github.com/systemjs/systemjs/blob/2.0.0/docs/package-name-maps.md

完成

如果您现在设法更新了代码,不妨在这里发布更新的示例,以供所有人使用。