【问题标题】:Angular2 - Import barrels cause 404 at runtimeAngular2 - 导入桶在运行时导致 404
【发布时间】:2016-09-08 02:53:00
【问题描述】:

我正在尝试实现此链接中描述的导入桶结构(您可能需要向下滚动一点):

https://angular.io/docs/ts/latest/guide/style-guide.html#!#application-structure

我面临的问题是我正在创建和引用的 index.ts 文件就像

import {...} from './shared/services';

在运行时找不到并抛出 404。如果我引用像

这样的模块
import {...} from './shared/services/index';

它工作正常。该问题仅在运行时出现,打字稿不抱怨并成功编译。我已经在 plunker 中复制了这个问题:

https://plnkr.co/edit/ClE76zuihFTETLDGehnd?p=preview

您可以在控制台中看到错误。

提前感谢您的帮助!

【问题讨论】:

  • 我可以自己重现这种行为。我会更深入地研究这个问题,如果我能找到一些东西,我会通知你

标签: import typescript angular


【解决方案1】:

我终于找到了一些东西:https://www.reddit.com/r/Angular2/comments/4i2d9x/support_problem_with_barrels/

看来,SystemJS 不容易做到这一点,因为它不能处理桶文件。

要解决这个问题,您可以像使用 [...]/index 一样添加每个文件,也可以将它们作为一个包添加到 SystemJS

【讨论】:

  • 确实如此!谢谢@Dinistro。我为所有 index.ts 文件添加了单独的包。 SystemJS的配置感觉可能有点臭,但整体代码干净了很多。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-12-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-05
相关资源
最近更新 更多