edgardleal / require-vuejs

RequireJS plugin to async and dynamic load and parse .vue components
https://edgardleal.github.io/require-vuejs/
MIT License
149 stars 30 forks source link

Does not work with ES6-Promise polyfill #43

Open cheresier opened 5 years ago

cheresier commented 5 years ago

I am trying to use this plugin in IE11 (as part of developing a non-transpiled Excel add-in, which run in an IE11 frame when used with Office desktop), so I have to rely on a polyfill to make promises work. While no error is thrown, Vue eventually times out trying to load the component. Wondering if there is a simple fix for that and looking forward to being able to use this seemingly awesome plugin.

edgardleal commented 5 years ago

Hi @cheresier , this looks to be an interesting project. Did you tried to increase the value of waitSeconds in requirejs setup ? https://requirejs.org/docs/api.html#config-waitSeconds

cheresier commented 5 years ago

Thank you for your response! Yes, I even set it to 0 to disable timeout altogether.

edgardleal commented 5 years ago

Hi @cheresier , can you post an example of code ?

cheresier commented 5 years ago

Sure! The quickest way to reproduce is to pretty much use your code from the https://github.com/edgardleal/require-vuejs#source-code-example page, but with <script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.js"></script> added above the require.js reference.

The polyfill above results in this error:

SCRIPT5022: Load timeout for modules: vue!component_unnormalized2,vue!component http://requirejs.org/docs/errors.html#timeout

I also tried using another polyfill: https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/7.4.3/polyfill.js

In this case the error above is preceded with another one: 2019-04-22 17_31_35-Require Vue - Internet Explorer

All this obviously applies to IE11. I will also add that the polyfill works correctly for other modern scripts I am using in this project (like vuetify)

racksen commented 5 years ago

After long struggling, I used the axios to replace the loadRemote(url) function. It worked in IE11.

FerdinandPiette commented 4 years ago

Hi, I had the same problem on ie11.

It is due to the definition of xhttp.timeout that should be placed after xhttp.open It is explain in MDN : https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/timeout This solve the problem.

return new Promise(function(resolve, reject) {
    var xhttp = new XMLHttpRequest();
    /* // IE11 : dont like timeout here
    xhttp.timeout = (
        (config.waitSeconds || config.timeout) || 3
    ) * 1000;//*/
    xhttp.onreadystatechange = function() {
        if (xhttp.readyState === 4
      && xhttp.status < 400) {
            var result = parse(xhttp.responseText);
            callback(result);
            resolve(result);
        }
    };
    xhttp.ontimeout = function() {
        var error = new Error("Timeout loading: " + path);
        callback({}, error);
        reject(error);
        throw error;
    };
    xhttp.open("GET", path, true);
    //* // Fix ie11 : timeout should be place here
    xhttp.timeout = (
        (config.waitSeconds || config.timeout) || 3
    ) * 1000;//*/
    xhttp.send();
});