【发布时间】:2020-06-01 11:15:17
【问题描述】:
我正在开发一个 React 应用程序,该应用程序报告了一个我正在摸不着头脑的问题,并且似乎很多人也遇到了这个问题。
所有解决问题的尝试均未成功,包括以下链接:
React app not rendering in IE 11 even with polyfills
https://github.com/facebook/create-react-app/issues/8197
我的 index.tsx 文件看起来像这样
import 'react-app-polyfill/ie11';
import 'react-app-polyfill/stable';
import 'fast-text-encoding/text';
import * as React from 'react'
import * as ReactDOM from 'react-dom'
import { hot } from 'react-hot-loader/root'
import App from './App'
我已将它包含在我的 package.json 文件中
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"ie 11",
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
IE11 控制台中的错误指向 bundle.js 作为问题,更具体地说是这些箭头函数。
const is = {
arr: Array.isArray,
obj: a => Object.prototype.toString.call(a) === '[object Object]', // This is where the error is reported.
fun: a => typeof a === 'function',
str: a => typeof a === 'string',
num: a => typeof a === 'number',
und: a => a === void 0,
nul: a => a === null,
set: a => a instanceof Set,
map: a => a instanceof Map,
equ(a, b) {
if (typeof a !== typeof b) return false;
if (is.str(a) || is.num(a)) return a === b;
if (is.obj(a) && is.obj(b) && Object.keys(a).length + Object.keys(b).length === 0) return true;
let i;
for (i in a) if (!(i in b)) return false;
for (i in b) if (a[i] !== b[i]) return false;
return is.und(i) ? a === b : true;
}
};
我的 ts 配置文件如下所示:
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"outDir": "./dist/",
"sourceMap": true,
"strict": true,
"noImplicitReturns": true,
"noImplicitAny": true,
"module": "es6", <=== //// Could this and target be something to do with the issue?
"moduleResolution": "node",
"target": "es5", <=== //// Could this and module be something to do with the issue?
"allowJs": true,
"checkJs": true,
"jsx": "react",
"baseUrl": ".",
"types": ["react", "node", "jest"],
"paths": {
"assets/*": ["src/assets/*"],
"config/*": ["src/config/*"],
"containers/*": ["src/containers/*"],
"hooks/*": ["src/hooks/*"],
"providers/*": ["src/providers/*"],
"routes/*": ["src/routes/*"],
"store/*": ["src/store/*"],
"tests/*": ["src/tests/*"],
"theme/*": ["src/assets/theme/*"],
"constants/*": ["src/utils/constants/*"],
"translations/*": ["src/translations/*"],
"utils/*": ["src/utils/*"],
"views/*": ["src/views/*"]
}
},
"include": ["./src/**/*", "tsconfig.json", "./typings/**/*.ts"]
}
我将不胜感激在此方面提供的任何和所有帮助,包括修复可能是什么、我需要调查哪些我可能错过了等等。
【问题讨论】:
标签: javascript reactjs babel-polyfill