首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Angular2系统问题

Angular2系统问题
EN

Stack Overflow用户
提问于 2016-02-02 15:06:02
回答 1查看 3.8K关注 0票数 2

我有一个简单的TypeScript角2例子:

test.ts

代码语言:javascript
运行
复制
import {Component} from 'angular2/core';

@Component({
    selector: 'my-app',
    template: '<div>Test</div>'
})

export class TestComponent {}

main.ts

代码语言:javascript
运行
复制
import {bootstrap} from 'angular2/platform/browser'
import {TestComponent} from './components/test.component/test'

bootstrap(TestComponent);

index.html

代码语言:javascript
运行
复制
<html>
    <head>
        <title>This is an Angular 2 test</title>

        <!-- Angular dependencies -->
        <script src="/node_modules/es6-shim/es6-shim.js"></script>
        <script src="/node_modules/systemjs/dist/system-polyfills.js"></script>
        <script src="/node_modules/angular2/bundles/angular2-polyfills.js"></script>
        <script src="/node_modules/systemjs/dist/system.src.js"></script>
        <script src="/node_modules/rxjs/bundles/Rx.js"></script>
        <script src="/node_modules/angular2/bundles/angular2.dev.js"></script>

        <!-- App -->
        <script>

            System.config({
                packages: {
                    '/': {
                        format: 'register',
                        defaultExtension: 'js'
                    }
                }
            });

            System.import('main').then(null, console.error.bind(console));

        </script>

    </head>
    <body>
        <my-app></my-app>
    </body>
</html>

最后,当我运行'tsc‘和我的部署脚本时,节点_模块/angular2 2,节点_模块/系统tsc,节点_模块/rxjs和节点_模块/es6-shim文件夹将与编译的JavaSciprt文件一起复制。然后,当我试图打开index.html时,我得到的只是:

代码语言:javascript
运行
复制
Uncaught ReferenceError: require is not defined(anonymous function) @ browser.ts:1

angular2-polyfills.js:138 Error: http://localhost:8080/node_modules/angular2/platform/browser.js did not call System.register or AMD define. If loading a global module configure the global name via the meta exports property for script injection support.(…)run @ angular2-polyfills.js:138zoneBoundFn @ angular2-polyfills.js:111lib$es6$promise$$internal$$tryCatch @ angular2-polyfills.js:1511lib$es6$promise$$internal$$invokeCallback @ angular2-polyfills.js:1523lib$es6$promise$$internal$$publish @ angular2-polyfills.js:1494lib$es6$promise$$internal$$publishRejection @ angular2-polyfills.js:1444(anonymous function) @ angular2-polyfills.js:243run @ angular2-polyfills.js:138zoneBoundFn @ angular2-polyfills.js:111lib$es6$promise$asap$$flush @ angular2-polyfills.js:1305

core.ts:6 Uncaught ReferenceError: require is not defined

有人能帮我一下这个吗?我似乎在做与Angular2 5分钟快速发车(https://angular.io/guide/quickstart)大致相同的事情,它只是拒绝为我工作。

我觉得我也需要将依赖库添加到systemjs中,但我不确定什么是正确的方法,以及angular2人员是如何让他们的quistart演示使用简单的<script></script>标记的。

tsconfig.json

代码语言:javascript
运行
复制
{
    "compilerOptions": {
        "target": "ES5",
        "module": "system",
        "moduleResolution" : "node",
        "sourceMap": true,
        "emitDecoratorMetadata": false,
        "experimentalDecorators": false,
        "removeComments": true,
        "noImplicitAny": true,
        "noEmitOnError": true,
        "outDir": "build"
    },

    "exclude": [
        "build",
        "bundle",
        "node_modules",
        "public",
        "scss",
        "html",
        "templates",
        ".sass-cache"
    ]
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-02 15:16:22

我认为问题在于您的SystemJS配置级别:

代码语言:javascript
运行
复制
System.config({
  packages: {
    '/': { <----------------
      format: 'register',
      defaultExtension: 'js'
    }
  }
});

您应该使用包含TypeScript源文件的子文件夹来更新它。就像这样:

代码语言:javascript
运行
复制
  System.config({
    packages: {        
      app: {
        format: 'register',
        defaultExtension: 'js'
      }
    }
  });

希望它能帮到你,蒂埃里

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35156966

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档