typescript 未捕获的类型错误:System.import 不是函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31462866/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 03:02:52  来源:igfitidea点击:

Uncaught TypeError: System.import is not a function

javascripttypescriptangularsystemjs

提问by Chris Bornhoft

This code is supposed to display a divcontaining Hello World, but instead I receive the error Uncaught TypeError: System.import is not a function. I'm following the getting started tutorial video for ng-book2, which contains the following code in index.html:

此代码应该显示div包含 Hello World,但我收到错误Uncaught TypeError: System.import is not a function。我正在关注 ng-book2 的入门教程视频,其中包含以下代码index.html

<!DOCTYPE html>
<html>
<head>
  <title>Angular 2</title>

  <script src="js/traceur-runtime-0.0.90.js"></script>
  <script src="js/system-0.18.4.js"></script>
  <script src="js/angular2-alpha31.js"></script>
</head>
<body>
  <script>System.import('js/app');</script>
  <hello-world></hello-world>
</body>
</html>

and app.ts:

app.ts

/// <reference path="../lib/node_modules/angular2/angular2.d.ts" />

import {
  Component,
  View,
  bootstrap
} from 'angular2/angular2';

// Annotation section
@Component({
  selector: 'hello-world'
})
@View({
  template: '<div>Hello World</div>'
})
// Component controller
class HelloWorld {

}

bootstrap(HelloWorld);

and finally the current directory structure:

最后是当前目录结构:

/ng2
  /js
    angular2-alpha31.js
    app.js
    app.js.map
    system-0.18.4.js
    system-0.18.4.js.map
    traceur-runtime-0.0.90.js
  index.html

Looking around for solutions, the only issue that seems similar enoughstates there's a problem with System's config.js. Except in this tutorial, the video shows this working without any hint of configuration. I should mention that this is being hosted on a remote server versus the local HTTP server used in the video.

四处寻找解决方案,唯一看起来足够相似的问题表明System 的config.js. 除了在本教程中,视频展示了这个工作,没有任何配置提示。我应该提到这是托管在远程服务器上,而不是视频中使用的本地 HTTP 服务器。

Screenshots of the developer window:

开发者窗口截图:

System.import is not a function

System.import 不是一个函数

File list

文件清单

Each file shown in the above directory structure is the most current available on GitHub as of writing this. Is there a default configuration file I should be including if I'm using a remote server or am I missing something else entirely?

在撰写本文时,上述目录结构中显示的每个文件都是 GitHub 上可用的最新文件。如果我使用的是远程服务器,或者我是否完全遗漏了其他内容,是否应该包含默认配置文件?

采纳答案by Chris Bornhoft

After playing around with the files further, I found that Angular2 is overriding SystemJS' Systemobject with its own. If angular2.jsmoved above system.jswithin the HTML, then the statement

在进一步处理这些文件后,我发现 Angular2 正在System用自己的对象覆盖 SystemJS 的对象。如果在 HTML 中angular2.js移动到上方system.js,则语句

<script>System.import('js/app');</script>

uses the correct System object.

使用正确的 System object。

This should not be happening, however it is an issue for the time being.

这不应该发生,但暂时是一个问题。

回答by basarat

Uncaught TypeError: System.import is not a function

未捕获的类型错误:System.import 不是函数

A tell tale indication that js/system-0.18.4.jsfailed to load.

js/system-0.18.4.js无法加载的告示指示。