【问题标题】:Angular 2 System src can't find core stuff (without packages)Angular 2 System src 找不到核心内容(没有包)
【发布时间】:2023-04-05 16:32:02
【问题描述】:

对 System.js 和 Angular 2 有一个有趣的问题。

在默认的快速入门中,我们有这个系统配置:

System.config({
      packages: {
        built: {
          format: 'register',
          defaultExtension: 'js'
        }
      }
    });
    System.import('built/main')
        .then(null, console.error.bind(console));

它对我有用。 但现在我尝试从构建的 upp 中移动所有文件。所以 main.js 文件与 index.html 位于一层。所以目前无法部署系统包。因为你需要一些文件夹名称(所有 node_modules 都正确安装在根文件夹中,所有 angular2 东西)。

我尝试使用一些简单的配置:

System.config({
       defaultJSExtensions: true
    });
    System.import('main')
        .then(null, console.error.bind(console));

但有很多这样的错误:

system.src.js:1061 获取 http://localhost:3000/angular2/platform/browser.js404 system.src.js:1061 获取http://localhost:3000/angular2/router.js 404 (未找到)

http://prntscr.com/ardlin

感谢您的帮助!

【问题讨论】:

  • 我认为这是因为系统不知道她必须在哪里寻找(node_module)。但这只是想法..

标签: angular config systemjs


【解决方案1】:

我认为您忘记包含 Angular2 捆绑文件:

<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="node_modules/angular2/bundles/router.dev.js"></script -->

因为 SystemJS 可以找到它们包含的模块,所以它会尝试从 .js 加载,因为您在其配置中将 defaultJSExtensions 属性设置为 true

【讨论】:

  • 嗨,蒂埃里,很高兴见到你 :) 不,很遗憾,我的 index.html 中包含所有捆绑包prntscr.com/ardx9n
  • 当我从系统配置中删除 defaultJsExtensions 时。 - 出现错误:angular2-polyfills.js:332 SyntaxError: Unexpected token
  • 嘿!我也是 ;-) 我认为你的进口有问题。尝试加载相应文件时似乎有404。你能检查一下吗?
  • 其实你是对的,但我不明白为什么。我从索引文件中得到 304,从系统中得到 404。 js prntscr.com/are2qz 我的导入:prntscr.com/are3wn 和 ts 文件:prntscr.com/are450
  • 回复正常:prntscr.com/are69t我认为系统配置有问题
【解决方案2】:

Thierry) 你又帮了我很多。谢谢朋友:)

为类似问题创建了您最古老的答案之一 Angular2 systemjs issues

你是对的。我们必须将所有 Angular js 文件保存在某个文件夹中。这个文件夹必须和 index.html 放在同级,像本地包一样注册。这是一个非常奇怪和有趣的规则,但无论如何。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-29
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    • 1970-01-01
    • 2017-12-15
    • 2020-01-20
    相关资源
    最近更新 更多