【问题标题】:TypeScript/Angular2: tagDef.requireExtraParent is not a functionTypeScript/Angular2:tagDef.requireExtraParent 不是函数
【发布时间】:2016-03-16 01:17:25
【问题描述】:

正在研究错误,

“异常:TypeError:tagDef.requireExtraParent 不是函数”

它实际上在 Google 上返回 0 个结果。

背景:

  • 网站在 Chrome 和 Safari 上运行良好。还没测试过IE。那里是完全不同的噩梦。
  • 错误仅适用于 Firefox(似乎是所有版本。目前为 45)
  • 我正在使用 System 从 TypeScript 转换为 ES5,并遵循 Angular 快速入门
  • 如果重要的话,在 Mac 上
  • Angular2,测试版 9

该网站非常基础。我已经消除了所有可能的并发症,而且似乎错误只是在引导本身。也许缺少 polyfill?

index.html

<script>
  System.config({
    transpiler: 'typescript', 
    typescriptOptions: { emitDecoratorMetadata: true }, 
    packages: {
        'js': {
            defaultExtension: 'js'
        }
    } 
  });
  System.import('js/main')
        .then(null, console.error.bind(console));

ma​​in.ts(入口点)

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

import {HTTP_PROVIDERS} from 'angular2/http';
import {bootstrap}    from 'angular2/platform/browser';
import {AppComponent} from './app/components/app';
import 'rxjs/Rx'

bootstrap(AppComponent, [HTTP_PROVIDERS]); // if i comment this out, the error disappears indicating that it lives somewhere in app.ts.

app.ts

import {Component} from 'angular2/core';

@Component({
    selector: "myapp",
    templateUrl: "templates/app.html",
    directives: [],
    providers: []
})

export class AppComponent {}

我尝试了什么

添加一些额外的 polyfill,例如 html_parser,这似乎是定义 requireExtraParent 方法的地方。

<script type="text/javascript" src="dist/lib/html_parser.js"></script>

消除任何编译/转译错误。

挖掘得如此之深,以至于 Google 甚至找不到任何东西。

【问题讨论】:

    标签: firefox typescript angular transpiler es6-shim


    【解决方案1】:

    你的解决方案很准确

    <script type="text/javascript" src="dist/lib/html_parser.js"></script>
    

    【讨论】:

    • 这样做后错误仍然存​​在,但是......?语法错误:导入声明只能出现在模块的顶层
    【解决方案2】:

    问题是我在 Angular 中使用了一个保留字作为标签(watch)。

    <services></services>
    <collage></collage>
    <watch></watch>  <== problem
    <collage></collage>
    

    把它改成这样就可以了:

    <services></services>
    <collage></collage>
    <watchit></watchit>  <== works fine
    <collage></collage>
    

    这是无法调试的。我不得不逐行注释,直到最终我发现它在 html 中,最终特别是哪一行引入了问题。

    只发布这样,如果其他人点击了这个,他们就不会那么疯狂。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-26
      • 1970-01-01
      • 2017-04-17
      • 1970-01-01
      相关资源
      最近更新 更多