未捕获的 ReferenceError:要求未在 angular2 中定义 [英] Uncaught ReferenceError: require is not defined in angular2
问题描述
<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 时,它显示Uncaught ReferenceError: require is not defined in angular2".我该如何克服这个错误.
without <script src="node_modules/angular2/upgrade.js"></script>
code works fine. when i include upgrade.js.it shows " Uncaught ReferenceError: require is not defined in angular2" .How can i overcome from this error.
推荐答案
require
函数由 SystemJS 提供.您需要将其添加到您的 script
中:
The require
function is provided by SystemJS. You need to add it into your 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=预览.
Here is a plunkr describing a working sample: https://plnkr.co/edit/JXLDFBW4A1mi9tyNHoJ3?p=preview.
希望对你有帮助蒂埃里
这篇关于未捕获的 ReferenceError:要求未在 angular2 中定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!