未捕获的Ref​​erenceError:需要在angular2没有定义 [英] Uncaught ReferenceError: require is not defined in angular2

查看:195
本文介绍了未捕获的Ref​​erenceError:需要在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>

没有code正常工作。当我有upgrade.js.it显示未捕获的Ref​​erenceError:需要在angular2没有定义。如何我可以从这个错误中克服

without "" 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.

推荐答案

要求功能由SystemJS提供。您需要将其添加到您的剧本

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/编辑/ JXLDFBW4A1mi9tyNHoJ3?p = preVIEW

Here is a plunkr describing a working sample: https://plnkr.co/edit/JXLDFBW4A1mi9tyNHoJ3?p=preview.

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

Hope it helps you, Thierry

这篇关于未捕获的Ref​​erenceError:需要在angular2没有定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆