[英]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>
without <script src="node_modules/angular2/upgrade.js"></script>
code works fine. 没有
<script src="node_modules/angular2/upgrade.js"></script>
代码工作正常。 when i include upgrade.js.it shows " Uncaught ReferenceError: require is not defined in angular2" .How can i overcome from this error. 当我包括upgrade.js.it显示“未捕获的ReferenceError:require未在angular2中定义”。如何克服此错误。
The require
function is provided by SystemJS. require
函数由SystemJS提供。 You need to add it into your script
: 您需要将其添加到
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>
(...)
Here is a plunkr describing a working sample: https://plnkr.co/edit/JXLDFBW4A1mi9tyNHoJ3?p=preview . 这是一个描述工作样本的plunkr: https ://plnkr.co/edit/JXLDFBW4A1mi9tyNHoJ3?p = preview。
Hope it helps you, Thierry 希望它对你有帮助,蒂埃里
Module should be system in tsconfig.json 模块应该是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"
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.