简体   繁体   English

无法在 IE11 中运行 React 应用程序:提供给“Provider”的道具“children”无效

[英]Can't get react app working in IE11: Invalid prop `children` supplied to `Provider`

I have a react app I need to add IE11 support to.我有一个需要添加 IE11 支持的 React 应用程序。 It's running, but there is an error which makes the app not usable.它正在运行,但有一个错误使应用程序无法使用。

The console complains that the prop type is incorrect (which other browser does not complain about):控制台抱怨 prop 类型不正确(其他浏览器没有抱怨):

Invalid prop `children` supplied to `ModalProvider`

I suspect that the issue is Symbol is not being (properly) polyfilled, since when I log the props.children object, it says something about Symbol and undefined , and there are many other issues on StackOverflow describing Symbol , IE11 and polyfill.我怀疑问题是Symbol没有(正确)polyfill,因为当我记录props.children对象时,它说一些关于Symbolundefined东西,并且 StackOverflow 上还有许多其他问题描述Symbol ,IE11 和 polyfill。 See screenshot below:请看下面的截图:

在此处输入图片说明

I have tried a lot of different solutions described, but can't remove this error, and therefore get the app to work properly.我尝试了许多描述的不同解决方案,但无法消除此错误,因此无法使应用程序正常运行。 Do you have any ideas?你有什么想法? 😊 😊

The project该项目

First off, the project is two separate react projects, where one (simple react-scripts app that just displays the imported/linked component, lets call it A ) links to the other (complex exported module, lets call it B ).首先,该项目是两个独立的反应项目,其中一个(简单的反应脚本应用程序,只显示导入/链接的组件,我们称之为A )链接到另一个(复杂的导出模块,我们称之为B )。 So I'm not entirely sure which one of them that should be polyfilled, or both.所以我不完全确定应该填充其中的哪一个,或者两者都填充。

Webpack.config.js for B : B 的Webpack.config.js
var path = require('path')

module.exports = {
  entry: {
    maps: './src/index.js'
  },
  output: {
    path: __dirname + '/dist',
    filename: 'index.js',
    library: 'Map',
    libraryTarget: 'umd'
  },
  module: {
    rules: [
      {
        test: /\.[s]?css$/,
        use: [
          'style-loader',
          {
            loader: 'css-loader',
            options: {
              importLoaders: 1,
              modules: true,
              localIdentName: '[local]--[sha1:hash:hex:4]'
            }
          },
          'sass-loader'
        ],
        include: /\.module\.[s]?css$/
      },
      {
        test: /\.[s]?css$/,
        use: ['style-loader', 'css-loader', 'sass-loader'],
        exclude: /\.module\.[s]?css$/
      },
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        use: ['babel-loader']
      },
      {
        test: /\.svg$/,
        use: ['@svgr/webpack']
      },
      {
        test: /\.(jpe?g|png)$/i,
        loader: 'file-loader?name=/public/icons/[name].[ext]'
      }
    ]
  },
  resolve: {
    modules: [
      path.resolve(__dirname, 'src'),
      path.resolve(__dirname, 'node_modules')
    ],
    extensions: ['.js', '.jsx']
  },
  externals: {
    // Use external version of React
    react: 'react',
    'react-dom': 'react-dom'
  },
  // NOTE: @claus added options to fix files not being watched
  watchOptions: {
    aggregateTimeout: 300,
    poll: 1000
  }
}
package.json browserlist for B : B 的package.json浏览器列表:
"browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all",
      "ie 11"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version",
      "ie 11"
    ]
  }
.babelrc for B : B 的.babelrc
{
  "presets": [
    ["@babel/preset-env"],
    "@babel/preset-react"],
  "plugins": ["@babel/plugin-proposal-object-rest-spread"]
}

Have you followed the below steps to support react app in IE 11?您是否按照以下步骤在 IE 11 中支持 React 应用程序?

  1. Install the package: npm install react-app-polyfill .安装包: npm install react-app-polyfill
  2. Add import 'react-app-polyfill/ie11'; import 'react-app-polyfill/stable';添加import 'react-app-polyfill/ie11'; import 'react-app-polyfill/stable'; import 'react-app-polyfill/ie11'; import 'react-app-polyfill/stable'; at the first line in src/index.js .src/index.js的第一行。
  3. Add ie 11 in packge.json like this:packge.json 中添加ie 11像这样:

在此处输入图片说明

  1. You can restart your app and it will work in IE11.您可以重新启动您的应用程序,它将在 IE11 中运行。

And I think you should polyfill both react projects to make both of them compatible with IE 11. If the error still persists, it could be better if you provide a minimal, reproducible sample so that we can test on our sides.而且我认为您应该对两个 react 项目进行 polyfill,使它们都与 IE 11 兼容。如果错误仍然存​​在,最好提供一个最小的、可重现的示例,以便我们可以进行测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React-Redux错误提供给提供者的对象类型为对象的无效子属性prop - React-Redux error Invalid prop `children` of type `object` supplied to `Provider` 反应错误'Failed propType:提供给`Provider`的无效道具`children`,期望一个ReactElement' - React error 'Failed propType: Invalid prop `children` supplied to `Provider`, expected a single ReactElement' React 应用程序在 IE11 中不起作用(尝试过 polyfills) - React app not working in IE11 (have tried polyfills) 获取使用在 IE11 中工作的 create-react-app 创建的应用程序 - Get application created using create-react-app working in IE11 React App - Bable Polyfill 无法正常工作 IE11 - React App - Bable Polyfill not working correctly IE11 Provider中的prop子项无效 - Invalid prop children in Provider “react-app-polyfill”在 IE11 中不起作用 - "react-app-polyfill" doesn't work in IE11 React Router-组成路线时提供给`Router`的无效道具`children' - React Router - Invalid prop `children` supplied to `Router` when composing routes 警告:道具类型失败:提供给“提供者”的对象类型为“对象”的道具儿童无效,需要一个ReactElement - Warning: Failed prop type: Invalid prop `children` of type `object` supplied to `Provider`, expected a single ReactElement 在IE11中反应应用程序崩溃 - React app crashes in IE11
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM