2016-08-03 7 views
-1

何が起こっているのかは不明ですが、このエラーによりページが表示されません。Bigcommerce Stencil:Javascriptエラー "オブジェクトがWindows SafariとIEでプロパティまたはメソッド 'assign'をサポートしていません

エラーメッセージは、bundle.jsファイル(webpack、babelなどのステンシルバンドル)を指しており、特にstencil-utilsパッケージのObject.assign()メソッドを指しています。それは27行目の@bigcommerce/stencil-utils/src/lib/request.js

ここでは、エラーを生成するコードのセクションです。

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': '{}', 
}; 

何が原因なのでしょうか?

答えて

2

あなたはObject.assignメソッドを使用していますが、それはすべてのブラウザでサポートされていません。 Internet ExplorerとSafari(Windows用)は、公式に更新されていません。

とにかく、Object.assignのpolyfillがあります。pageです。あなたはコードの上にそれを適用することができます。

これは自分自身のポリフィルで、オブジェクト/アレイ参照の作成を避けることができます(ただし、Imageなどの追加インターフェイスを使用するオブジェクトを除く)。

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

助けてくれてありがとうございました。webpackにbabel-polyfillパッケージを追加できました。修正されました。 – enjoyjeremy

関連する問題