【问题标题】:Angular 2 not rendering dependancy links with file extensionsAngular 2 不呈现带有文件扩展名的依赖链接
【发布时间】:2016-03-23 23:46:36
【问题描述】:

我在运行我的应用时遇到以下错误:

它似乎在寻找./app.component,而不是./app.component.js

这是我的main.ts 文件:

import { bootstrap }    from 'angular2/platform/browser';
import { AppComponent } from './app.component';

bootstrap(AppComponent);

我在此处配置依赖项做错了什么?注意:如果我将引用更改为import { AppComponent } from './app.component.js';,那么错误就会消失,并且对于其他引用,我将面临更多相同的错误。

编辑:

其中一位 cmets 建议我的 system.config() 可能存在问题,我认为这听起来很合理,但是,这是我的 index.html 文件的摘录,我看不到任何文件有问题吗?

...    
<script>
  System.config({
    packages: {        
      app: {
        format: 'register',
        defaultExtension: 'js'
      }
    }
  });
  System.import('client/dev/main.js')
        .then(null, console.error.bind(console));
</script>
...

【问题讨论】:

  • 问题出在您的 System.config() 中,可能缺少 defaultExtension 或类似名称。发布您的配置并查看 quickstart guide(查找 SystemJS 配置
  • @EricMartinez,我已经设置了我的 System.Config,但我仍然遇到这些问题。请查看我添加到问题中的 index.html 文件,可以吗?

标签: javascript angularjs angular


【解决方案1】:

你的错误可能是你有:

<script>
  System.config({
    packages: {        
      app: {
        format: 'register',
        defaultExtension: 'js'
      }
    }
  });
  System.import('client/dev/main.js')
        .then(null, console.error.bind(console));
</script>

而不是

<script>
  System.config({
    packages: {       
      "client/dev": { // this line changed, here the directory where your generated `js` files are, has to be specified 
        format: 'register',
        defaultExtension: 'js'
      }
    }
  });
  System.import('client/dev/main')
        .then(null, console.error.bind(console));
</script>

我刚开始时遇到的问题和你一模一样;)

如果您使用最新的 angular beta 版本 (12),zone 错误应该会消失。

【讨论】:

  • 这引发了一个新问题here,如果您有机会,我将非常感谢您的意见。
猜你喜欢
  • 2010-09-13
  • 1970-01-01
  • 2020-04-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-18
  • 2011-01-29
相关资源
最近更新 更多