(SystemJS) module is not defined

别来无恙 提交于 2019-12-12 03:42:15

问题


I am getting this error when trying to load angular2 page:

https://postimg.org/image/meg0l2znn/

My index.html

<!DOCTYPE html>
<html>
<head>
    <title>Reloyalty Administration Dashboard</title>

    <!-- Viewport mobile tag for sensible mobile support -->
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="icon" href="/favicon.ico">

    <!-- For Angular2 Routing -->
    <base href="/">


    <!-- Common Scripts-->
    <script src="/common/js/jquery-1.11.3.min.js"></script>

    <!--SCRIPTS-->
    <script src="/bootstrap/js/bootstrap.min.js"></script>
    <script src="/dashboard/js/bootstrap-switch.js"></script>
    <script src="/dashboard/js/calendar-conf-events.js"></script>
    <script src="/dashboard/js/chartjs-conf.js"></script>
    <script src="/dashboard/js/common-scripts.js"></script>
    <script src="/dashboard/js/easy-pie-chart.js"></script>
    <script src="/dashboard/js/form-component.js"></script>
    <script src="/dashboard/js/gritter-conf.js"></script>
    <script src="/dashboard/js/jquery-ui-1.9.2.custom.min.js"></script>
    <script src="/dashboard/js/jquery.backstretch.min.js"></script>
    <script src="/dashboard/js/jquery.dcjqaccordion.2.7.js"></script>
    <script src="/dashboard/js/jquery.nicescroll.js"></script>
    <script src="/dashboard/js/jquery.scrollTo.min.js"></script>
    <script src="/dashboard/js/jquery.sparkline.js"></script>
    <script src="/dashboard/js/jquery.tagsinput.js"></script>
    <script src="/dashboard/js/jquery.ui.touch-punch.min.js"></script>
    <script src="/dashboard/js/sparkline-chart.js"></script>
    <script src="/dashboard/js/tasks.js"></script>
    <script src="/dashboard/js/zabuto_calendar.js"></script>
    <script src="/dashboard/js/bootstrap-inputmask/bootstrap-inputmask.min.js"></script>
    <script src="/dashboard/js/chart-master/Chart.js"></script>
    <script src="/dashboard/js/fancybox/jquery.fancybox.js"></script>
    <script src="/dashboard/js/fullcalendar/fullcalendar.min.js"></script>
    <script src="/dashboard/js/gritter/js/jquery.gritter.js"></script>
    <script src="/dashboard/js/jquery-easy-pie-chart/jquery.easy-pie-chart.js"></script>
    <script src="/js/node_modules/es6-shim/es6-shim.min.js"></script>
    <script src="/js/node_modules/reflect-metadata/Reflect.js"></script>
    <script src="/js/node_modules/systemjs/dist/system-polyfills.js"></script>
    <script src="/js/node_modules/systemjs/dist/system.src.js"></script>
    <script src="/js/node_modules/zone.js/dist/zone.js"></script>
    <script src="/js/node_modules/rxjs/bundles/Rx.js"></script>
    <!--SCRIPTS END-->

    <script>



        System.config({
            packages: {
                app: {
                    format: 'register',
                    defaultExtension: 'js',
                    main: './main.js'
                },
                '@angular/core': {
                    main: 'bundles/core.umd.js',
                    defaultExtension: 'js'
                },
                '@angular/compiler': {
                    main: 'bundles/compiler.umd.js',
                    defaultExtension: 'js'
                },
                '@angular/common': {
                    main: 'bundles/common.umd.js',
                    defaultExtension: 'js'
                },
                '@angular/platform-browser-dynamic': {
                    main: 'bundles/platform-browser-dynamic.umd.js',
                    defaultExtension: 'js'
                },
                '@angular/platform-browser': {
                    main: 'bundles/platform-browser.umd.js',
                    defaultExtension: 'js'
                },
                rxjs: {
                    main: 'bundles/Rx.umd.min.js',
                    defaultExtension: 'js'
                }
            },
            map: {
                'app': 'management', // where my app is. '.' means relative
                '@angular': '/js/node_modules/@angular',
                'rxjs': '/js/node_modules/rxjs'
            }
        });
        System.import('app')
                .then(null, console.error.bind(console));
    </script>

    <!-- end AngularJS 2-->
</head>

<body>

<root-component>Loading...</root-component>

</body>
</html>

What is going on ? Why is it not finding SystemJS ...

NOTE: My folder structure is that the app is located under assets/management folder like so:

management/
├── app/
|   ├──root/
│       ├── root.component.ts
|       ├── root.module.ts
├──main.ts

NOTE2: removing System.import ... results in the error not being thrown

System.import('app')
                .then(null, console.error.bind(console));

回答1:


I bet you need to first load system.src.js and then system-polyfills.js. You're doing it the other way around now.

<script src="/js/node_modules/systemjs/dist/system.src.js"></script>
<script src="/js/node_modules/systemjs/dist/system-polyfills.js"></script>

See: https://github.com/systemjs/systemjs#promise-polyfill



来源:https://stackoverflow.com/questions/40465367/systemjs-module-is-not-defined

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!