[英]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
对象时,它说一些关于Symbol
和undefined
东西,并且 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?你有什么想法? 😊 😊
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 应用程序?
npm install react-app-polyfill
.安装包: npm install react-app-polyfill
。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的第一行。ie 11
in packge.json like this:在packge.json 中添加ie 11
像这样: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.