Uncaught ReferenceError: require is not defined in angular2

梦想的初衷 提交于 2019-12-01 16:40:24

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>
(...)

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

Hope it helps you, Thierry

Jayesh Sharma

Module should be system in 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"
    ]
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!