2016-08-03 13 views
-1

Nicht sicher, was passiert, aber dieser Fehler verhindert die Seite anzuzeigen.BigCommerce Stencil: Javascript Fehler "Objekt unterstützt keine Eigenschaft oder Methode 'zuweisen'" in Windows Safari und IE

Die Fehlermeldung zeigt auf meine Bundle.js-Datei (Schablonenbündel mit Webpack, Babel, etc) und speziell auf die Object.assign()-Methode im Schablonen-Utils-Paket. Es ist Linie 27 von @bigcommerce/stencil-utils/src/lib/request.js

Hier ist der Abschnitt des Codes, der den Fehler erzeugt.

const defaultOptions = { 
    method: 'GET', 
    remote: false, 
    requestOptions: { 
     formData: null, 
     params: {}, 
     config: {}, 
     template: [], 
    }, 
}; 
const options = Object.assign({}, defaultOptions, opts); 
const data = options.requestOptions.formData ? options.requestOptions.formData : options.requestOptions.params; 
const headers = { 
    'stencil-config': options.requestOptions.config ? JSON.stringify(options.requestOptions.config) : '{}', 
    'stencil-options': '{}', 
}; 

Irgendwelche Ideen, was könnte dies verursachen?

Antwort

2

Es passiert, dass Sie die Object.assign Methode verwenden, die nicht von allen Browsern unterstützt wird. Internet Explorer und Safari (für Windows) werden nicht mehr offiziell aktualisiert.

Wie auch immer, es gibt eine Polyfill von Object.assign in diesem page. Sie können es oben im Code anwenden.

Dies ist meine eigene Polyfill, die optional vermeidet, Objekte/Arrays Referenzen zu erstellen (mit Ausnahme von Objekten mit einer zusätzlichen Schnittstelle wie Image, etc ...).

typeof Object.assign !== "function" && 

(function() { 

    /** 
    * Return main instance of value. 
    * @param {...} value 
    * @returns 
    */ 
    function getMainInstance(value) { 
     // get instance in this format: [object Instance] 
     var ic = Object.prototype.toString.call(value); 
     // returns string between '[object ' and ']' 
     return ic.substring(ic.indexOf(" ") + 1, ic.lastIndexOf("]")).toLowerCase(); 
    } 


    Object.assign = function(target) { 

     /* check if target isn't a object */ 
     if (typeof target !== "object") target = {}; 

     /* last target path */ 
     var lastPath = target; 

     /* list containing target paths */ 
     var locations = []; 

     /* consume specific array/object */ 
     function consume(source) { 
      /* iterate each property to copy */ 
      for (var i in source) { 
       var instance = getMainInstance(source[i]); 
       if (instance === "object" || instance === "array") { 
        lastPath = 
        lastPath[i] = 
        locations[locations.length] = (instance === "array" ? [] : {}) 

        consume(source[i]); 

       } else { 
        lastPath[i] = source[i]; 
       } 
      } 

      var len = -- locations.length; 
      lastPath = locations[--len] || target; 

     } 

     for (var i = 1, source; source = arguments[i]; i++) { 
      if (typeof source === "object") consume(source); 
     } 

     return target; 
    }; 

})(); 
+2

Danke für die Hilfe, ich konnte das babel-polyfill Paket webpack hinzuzufügen und es geregelt! – enjoyjeremy

Verwandte Themen