Preset在IE11上不提供对Object

Preset在IE11上不提供对Object

本文介绍了Babel Preset在IE11上不提供对Object.assign的支持-"Object不支持属性或方法'assign'".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我为我的React应用程序使用 babel-preset-env版本-1.6.1 ,我在IE上收到错误:-对象不支持属性或方法'assign '

I am using babel-preset-env version - 1.6.1 for my react app, i am getting a error on IE :- Object doesn't support property or method 'assign'

这是我的 .babelrc :-

{
"presets": [
    "react",
    [
        "env",
        {
            "targets": {
                "browsers": [
                    "last 1 versions",
                    "ie >= 11"
                ]
            },
            "debug": true,
            "modules": "commonjs"
        }
    ]
],
"env": {
    "test": {
        "presets": [
            [
                "babel-preset-env",
                "react"
            ]
        ],
        "plugins": [
            "transform-object-rest-spread",
            "transform-class-properties",
            "transform-runtime",
            "babel-plugin-dynamic-import-node",
            "array-includes",
            "url-search-params-polyfill",
            "transform-object-assign"
        ]
    }
},
"plugins": [
    "transform-object-rest-spread",
    "transform-class-properties",
    "syntax-dynamic-import",
    "transform-runtime",
    "array-includes",
    "url-search-params-polyfill",
    "transform-object-assign"
]

}

我尝试了这些polyfills:-

i tried these polyfills :-

https://babeljs.io/docs/plugins/transform-object-assign / https://www.npmjs.com/package/babel-plugin-object-assign

但没有用

我正在使用语法:-

let a = Object.assign({},obj);

项目中的任何地方

我需要一个适用于我的项目的polyfill.

i need a polyfill that would work for my project.

推荐答案

您需要 Babel Polyfill .

将其导入您的入口JS文件中,或使用Webpack.

Either import it in your entry JS file, or use Webpack.

import "babel-polyfill";

或在webpack.config.js

module.exports = {
  entry: ["babel-polyfill", "./app/main"]
}

注意:babel-polyfill应该在最上面导入,否则将不起作用

NOTE : babel-polyfill Should be imported on very top else It will not work

这篇关于Babel Preset在IE11上不提供对Object.assign的支持-"Object不支持属性或方法'assign'".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 12:01