You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Webpack4+MobX State Tree+Babel环境下IE11报Object.assign错误,选哪个Babel插件?

解决IE11中MobX State Tree的Object.assign错误

Hey there! Let's work through this IE11 error together. First, the root cause is clear: IE11 doesn't natively support Object.assign, and the error is popping up in mobx-state-tree's library code (not your own source files)—that's a critical detail here.

两者的核心区别

  • babel-plugin-transform-object-assign
    This plugin only transforms Object.assign calls in your own project code, converting them into compatibility-friendly equivalent logic. However, it won't touch code inside node_modules (like mobx-state-tree's files). Since your error comes from a third-party library, this plugin can't fix the problem for you.

  • babel-polyfill
    It works by adding missing JavaScript APIs to the global environment, including Object.assign. Once you include it, every piece of code—whether yours or a third-party library's—will use this polyfilled implementation when calling Object.assign. This is exactly what you need here, because the error originates from mobx-state-tree's code.

推荐解决方案

Go with babel-polyfill (or the more modern core-js, which is the recommended approach for Babel 7+):

  1. Install the dependency:
    npm install --save babel-polyfill
    
  2. Import it at the very top of your project's entry file (like index.js):
    import 'babel-polyfill';
    

For Babel 7+ users, a better practice is to use core-js with @babel/preset-env to auto-include only the polyfills IE11 needs:

  • Install core-js:
    npm install --save core-js@3
    
  • Update your Babel config:
    {
      "presets": [
        [
          "@babel/preset-env",
          {
            "targets": {
              "ie": "11"
            },
            "useBuiltIns": "usage",
            "corejs": 3
          }
        ]
      ]
    }
    
    This setup will automatically inject required polyfills (including Object.assign) based on your target browser, no manual import needed.

总结

Since your error comes from a third-party library, babel-plugin-transform-object-assign can't help—it only processes your own code. You need babel-polyfill (or core-js) to globally patch the missing Object.assign API, so IE11 can run mobx-state-tree correctly.

内容的提问来源于stack exchange,提问作者chobo2

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:33:07