简体   繁体   English

升级到Angular2时未定义系统

[英]System not defined when upgrading to Angular2

As per the official guidelines on upgrading an angular1 app to angular2 you need to include the system.src.js file and then load the application in like so: 根据有关将angular1应用程序升级到angular2的官方指南 ,您需要包括system.src.js文件,然后像这样加载应用程序:

    System.config({
      packages: {'js': {defaultExtension: 'js'}}
    });
    System.import('/js/app.module');

This points to an expected app.module.ts file that is the main component of the application. 这指向预期的app.module.ts文件,该文件是应用程序的主要组件。 However this code isn't even getting this far as it complains: 但是,该代码甚至还没有达到它所抱怨的程度:

Uncaught ReferenceError: System is not defined

Which made me think that it isn't loading the system.src.js file correctly. 这使我认为它没有正确加载system.src.js文件。 But I've tried loading it via gulp, which concats and places all my js files into one file ie main.js - no success, and I've tried including it seperately eg 但是我尝试通过gulp加载它,将所有js文件合并并放置到一个文件(即main.js -没有成功,并且我尝试了单独包含它

dist
    js
        main.js
        system.src.js

and adding a script tag for this version: 并为此版本添加脚本标签:

// Loaded before the import statement above so it's definitely there
%script{src: "js/system.src.js", async: true}
%script{src: "js/main.js", async: true}

but neither of these ways actually work. 但是这两种方式都不可行。 I can even see it as a source file in the dev window so it's there - so am I missing something else? 我什至可以在开发窗口中将其视为源文件,所以就在那里-我是否还缺少其他东西?

Thanks 谢谢

Have you checked your tsconfig? 您检查过tsconfig了吗?

{
  "compilerOptions": {
    "target": "ES5",
    "module": "system",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "removeComments": false,
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true
  },
  "exclude": [
    "node_modules"
  ]
}

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

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