7
<html>
<head>
<title>Angular 2 QuickStart</title>
<!-- 1. Load libraries -->
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/rxjs/bundles/Rx.umd.js"></script>
<script src="node_modules/angular2/bundles/angular2-all.umd.js"></script>
<!-- 2. Load our 'modules' -->
<script src='app/app.component.js'></script>
<script src='app/boot.js'></script>

<!--upgrade-->
<script src="node_modules/angular2/upgrade.js"></script>
</head>
<!-- 3. Display the application -->
<body>
<my-app>Loading...</my-app>
</body>
</html>

没有<script src="node_modules/angular2/upgrade.js"></script>代码工作正常。当我包含 upgrade.js.it 显示“Uncaught ReferenceError: require is not defined in angular2”。我该如何克服这个错误。

4

2 回答 2

-1

require功能由 SystemJS 提供。您需要将其添加到您的script

<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/rxjs/bundles/Rx.umd.js"></script>
<script src="node_modules/angular2/bundles/angular2-all.umd.js"></script>
(...)

这是一个描述工作示例的 plunkr:https ://plnkr.co/edit/JXLDFBW4A1mi9tyNHoJ3?p=preview 。

希望它可以帮助你,蒂埃里

于 2016-01-19T10:36:39.930 回答
-3

模块应该是 tsconfig.json 中的系统

{
    "version": "1.0.0",
    "compilerOptions": {
        "target": "es5",
        **"module": "system",**
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "noImplicitAny": false,
        "noLib": false,
        "declaration": false
    },
    "exclude": [
        "node_modules",
        "bower_components",
        "jspm_packages",
        "typings/main",
        "typings/main.d.ts"
    ]
}
于 2016-07-09T09:20:38.790 回答