Asp.net MVC5 angular4未捕获引用错误:部署到IIS后系统未在systemjs.config.js中定义

时间:2017-12-27 08:23:52

标签: asp.net angular asp.net-mvc-5 iis-7

我创建了Asp.Net MVC Angular2应用程序,它在visual studio2017外部主机中运行时工作正常。但是当我发布这个应用程序并通过IIS运行时。我收到错误

未捕获的ReferenceError:

中未定义系统
  1. systemjs.config.js和
  2. _Layout.cshtml

          System.import('app')。catch(function(err){console.error(err);});
  3. 下面是我的Bundle.config类:

    public class BundleConfig
    {
         public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js"));
    
            bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                        "~/Scripts/jquery.validate*"));
    
            bundles.Add(new ScriptBundle("~/bundles/angular").Include(                
                       "~/node_modules/core-js/client/shim.min.js",
                       "~/node_modules/systemjs/dist/system-polyfills.js",                                 
                       "~/node_modules/zone.js/dist/zone.js",
                       "~/node_modules/systemjs/dist/system.src.js",
                       "~/node_modules/systemjs/dist/system.js",
                       "~/systemjs.config.js"
                       ));
    
            bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                        "~/Scripts/modernizr-*"));
    
            bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(                      
                      "~/Scripts/bootstrap.min.js",                      
                      "~/Scripts/respond.js"                       
                      ));
    
            bundles.Add(new StyleBundle("~/Content/css").Include(
                      "~/Content/bootstrap.min.css",
                      "~/Content/font-awesome.min.css",
                      "~/Content/animate.min.css",
                      "~/node_modules/angular2-busy/build/style/busy.css",
                      "~/node_modules/ng2-toastr/bundles/ng2-toastr.min.css",
                       "~/Content/custom.css"                       
                      ));          
        }
    }
    

    systemjs.config.js

     (function (global) {
            SystemJS.config({        
            paths: {
                'npm:': 'node_modules/'
            },
            map: {
              'app': 'app',
    
              '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
              '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
              '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
              '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
              '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
              '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
              '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
              '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
              '@angular/animations': 'npm:@angular/animations/bundles/animations.umd.js',
              '@angular/animations/browser': 'npm:@angular/animations/bundles/animations-browser.umd.js',
              '@angular/platform-browser/animations': 'npm:@angular/platform-browser/bundles/platform-browser-animations.umd.js', 
              'file-saver': 'npm:file-saver/',
              'angular2-busy': 'npm:angular2-busy',
    
              'ng2-smart-table': 'npm:ng2-smart-table',
              'ng2-completer': 'npm:ng2-completer',
              'ng2-bs3-modal': 'npm:/ng2-bs3-modal',
              'lodash': 'npm:lodash',
              'rxjs': 'npm:rxjs',
              'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
              'mydatepicker': 'npm:mydatepicker/bundles/mydatepicker.umd.min.js',
              'ng2-toastr': 'npm:ng2-toastr',
    
              'moment': 'npm:moment',
              'ngx-pipes': 'npm:ngx-pipes/bundles/ngx-pipes.umd.min.js'
    
            },
            packages: {
                    app: { main: 'main.js', defaultExtension: 'js' },
                    rxjs: { defaultExtension: 'js' },
                    'ng2-bs3-modal': { main: '/bundles/ng2-bs3-modal.js', defaultExtension: 'js' },
                    'ng2-smart-table': { main: 'bundles/table.umd.js', defaultExtension: 'js' },
                    'ng2-completer': { main: 'ng2-completer.umd.js', defaultExtension: 'js' },
                    'lodash': { main: 'lodash.js', defaultExtension: 'js' },
                    'file-saver': { format: 'global', main: 'FileSaver.js', defaultExtension: 'js'},
                    'angular2-busy': { main: './index.js', defaultExtension: 'js' },
                    'moment': { main: 'moment', defaultExtension: 'js' },            
                    'ng2-toastr': { main: '/bundles/ng2-toastr.min.js', defaultExtension: 'js' },     
                }
          });
        })(this);
    

1 个答案:

答案 0 :(得分:0)

我找到了一个解决方法,我将我的node_modules文件夹从我的项目复制到发布包,看到错误消失了