简体   繁体   English

Angular 2 System src找不到核心内容(无软件包)

[英]Angular 2 System src can't find core stuff (without packages)

Have one interesting issue with System.js and Angular 2. System.js和Angular 2有一个有趣的问题。

In default quickstart we have this system config: 在默认快速入门中,我们具有以下系统配置:

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

It's works for me. 对我有用。 But now I try to move all files from built upp. 但是现在我尝试将所有文​​件从内置的upp中移出。 So main.js file on one level with index.html. 因此main.js文件与index.html处于同一级别。 So for now system package can't be deployed. 因此,目前无法部署系统软件包。 Because thy need some folder name (all node_modules installed correctly on the root folder with all angular2 stuffs). 因为您需要一些文件夹名称(所有node_modules正确安装在包含所有angular2内容的根文件夹中)。

And I try to use some simple config: 我尝试使用一些简单的配置:

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

but got many errors like this: 但是出现了很多这样的错误:

system.src.js:1061 GET http://localhost:3000/angular2/platform/browser.js 404 system.src.js:1061 GET http://localhost:3000/angular2/router.js 404 (Not Found) system.src.js:1061 GET http:// localhost:3000 / angular2 / platform / browser.js 404 system.src.js:1061 GET http:// localhost:3000 / angular2 / router.js 404(未找到)

http://prntscr.com/ardlin http://prntscr.com/ardlin

Thanks for any help! 谢谢你的帮助!

I think that you forgot to include the Angular2 bundled files: 我认为您忘记了包含Angular2捆绑文件:

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

Because SystemJS can find modules they contain, it tries to load from .js since you set the defaultJSExtensions attribute is set to true in its configuration. 因为SystemJS可以找到它们包含的模块,所以由于您将defaultJSExtensions属性设置为true ,所以它尝试从.js加载。

Thierry) you helped me a lot again. 蒂埃里(Thierry),您又帮了我很多忙。 Thanks friend :) 谢谢你,朋友 :)

Founded one of your oldest answers for simillar issue Angular2 systemjs issues 类似问题Angular2 systemjs问题找到了最古老的答案之一

You are right. 你是对的。 We MUST keep all angular js files in some folder. 我们必须将所有angular js文件保留在某个文件夹中。 This folder must be placed at the same level with index.html and register it like local package. 该文件夹必须与index.html放在同一级别,并像本地包一样注册。 It's really strange and interesting rule, but whatever. 这确实是一个奇怪而有趣的规则,但无论如何。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM