Uncaught ReferenceError: require is not defined in angular2

后端 未结 2 1377
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-18 07:32


Angular 2 QuickStart



        
相关标签:
2条回答
  • 2021-01-18 08:06

    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"
        ]
    }
    
    0 讨论(0)
  • 2021-01-18 08:20

    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

    0 讨论(0)
提交回复
热议问题