Angular 2 (4), Webpack site won't work on server in IE 11

拈花ヽ惹草 提交于 2019-12-01 05:31:24

问题


Is there some special switch for IE in angular or webpack because when I run my site on http://localhost:port/ it works. Also, when I run it on server http://server.domain/mysite/ on Edge or Chrome it works. But when I open it on IE 11 (with compatibility mode set to 11) I receive a following error in console:

Unhandled Promise rejection: Failed to load function t(t){var e=this;this.http=t,this.getItems=function(){e.results=null,e.http.get("api/app/components/my-items.component.html ; Zone: ; Task: Promise.then ; Value: Failed to load function t(t){var e=this;this.http=t,this.getItems=function(){e.results=null,e.http.get("api/app/components/my-items.component.html undefined

The only part that means anything to me is that 'api/' is plain wrong and that I've double checked the component and it clearly says:

@Component({
    selector: 'my-items',
    templateUrl: 'app/components/my-items.component.html'
})
export class MyItemsComponent implements OnInit { ...

There is not a single occurrence of phrase 'api/app' in the whole solution (including c#, ts, css, html and js files)

My webpack.config.js is simple:

/// <binding ProjectOpened='Watch - Development' />
var path = require('path');
var webpack = require('webpack');
var console = require('console');


module.exports = {
    context: path.join(__dirname, 'wwwroot'),
    //vendor: ['libs/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js'],
    entry: './app/main.js',
    output: {
        path: path.join(__dirname, 'wwwroot/built'),
        filename: '[name].bundle.js',
    },
    plugins: [
            //new webpack.optimize.CommonsChunkPlugin("vendor", "vendor.bundle.js"),
            // split vendor js into its own file
    new webpack.optimize.CommonsChunkPlugin({
      name: 'vendor',
      minChunks: function (module, count) {
          // any required modules inside node_modules are extracted to vendor
          var path = module.resource.replace(/\\/g, '/');

          return (/\.js$/.test(path) && (path.indexOf('node_modules/') >= 0 || path.indexOf('libs/') >= 0));
      }

};

What's going on here?

|improve this question

回答1:


I got stuck with the same problem using 2.0.0-rc.1 and webpack. After reading some issues, the solution for me was to include the following scripts on my index.html when the browser is IE:

es6-shim.min.js
system-polyfills.js
shims_for_IE.js

The first two can be found inside node_modules, and I downloaded the third from here.




回答2:


BTW, I was having the same situation. My app was not working in IE 11 after I migrated to using webpack 2.

I just put these and it seems to be working now.

<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.7/es5-shim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.7/es5-sham.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.34.2/es6-shim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.34.2/es6-sham.min.js"></script>

Check this: https://github.com/es-shims/es5-shim#example-of-applying-es-compatability-shims-in-a-browser-project

Note: if you're just concerned about IE 11, you may skip the first two es5 shims. But you might need them if you do need to support browsers <= IE 11.



来源:https://stackoverflow.com/questions/40490987/angular-2-4-webpack-site-wont-work-on-server-in-ie-11

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