我在Redux上使用React,但在IE上遇到了麻烦。仅在IE上不起作用。
当我仅使用反应构建应用程序时,它可以工作,因此我猜想它与Redux有关。它为应用返回未定义,并且redux-logger显示此错误:
SCRIPT438:对象不支持属性或方法“分配”
我的webpack:
const path = require("path");
const componentName = "contact-captain";
const publicFolderRelativePath = "../../../../public/js";
module.exports = {
output: {
path: path.resolve(__dirname, publicFolderRelativePath),
filename: `${componentName}.js`
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
}
]
}
};
package.json
{
"name": "temp",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"watch": "webpack -w --mode development --progress --color --display-error-details",
"build": "webpack --mode production"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/plugin-transform-object-assign": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.2",
"react": "^16.4.2",
"react-dom": "^16.4.2",
"react-redux": "^5.0.7",
"redux": "^4.0.0",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0",
"webpack": "^4.17.1",
"webpack-cli": "^3.1.0"
},
"dependencies": {
"axios": "^0.18.0",
"lodash": "^4.17.10",
"moment": "^2.22.2"
}
}
.babelrc
{
"presets": ["@babel/preset-env", "@babel/preset-react"],
"plugins": [ "@babel/plugin-transform-object-assign"]
}
当我使用babel-polyfill时它可以工作,但是我不能使用它,因为在加载babel-polyfill的页面上已经使用过,因此它返回该不同组件的错误。
答案 0 :(得分:1)
添加此内容对我有帮助
if (typeof Object.assign != 'function') {
Object.assign = function(target) {
'use strict';
if (target == null) {
throw new TypeError('Cannot convert undefined or null to object');
}
target = Object(target);
for (var index = 1; index < arguments.length; index++) {
var source = arguments[index];
if (source != null) {
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
}
return target;
};
}
答案 1 :(得分:0)
考虑将https://babeljs.io/docs/en/babel-plugin-transform-object-assign添加到您的.babelrc中,以使其正常工作