【发布时间】:2018-03-20 02:02:52
【问题描述】:
我正在尝试添加对 IE11 的支持。我得到错误:
SCRIPT1003:预期为“:”
文件:vendor.bundle.js,行:8699,列:8
SCRIPT5009: 'webpackJsonp' 未定义
文件:app.bundle.js,行:1,列:1
第 8699 行抛出:
style(props, propName, componentName) {
if (props[propName] == null) {
return undefined;
}
似乎 babel 没有将这个 Object Initializer 转换为 style: (props, propName, componentName)。
package.json:
"babel-core": "^6.26.0",
"babel-eslint": "^8.2.2",
"babel-loader": "^7.0.0",
"babel-plugin-istanbul": "^4.1.4",
"babel-plugin-relay": "^1.4.1",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.16.0",
"babel-preset-stage-2": "^6.22.0",
"babel-register": "^6.18.0",
.babelrc
{
"presets": [
"env",
"stage-2",
"react"
],
"plugins": [
"relay"
],
}
webpack.js:
{
test: /\.jsx?$/,
include: [
path.resolve(__dirname, 'wwwroot/components'),
],
loader: 'babel-loader',
},
我认为第二个错误是由第一个错误引起的。
编辑:
完整的错误代码:
var _StyleValidator = __webpack_require__(1396);
var _StyleValidator2 = _interopRequireDefault(_StyleValidator);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var styleValidator = exports.styleValidator = new _StyleValidator2.default();
function configStyleValidator(config) {
styleValidator.setConfig(config);
}
exports.default = {
style(props, propName, componentName) {
if (props[propName] == null) {
return undefined;
}
for (var _len = arguments.length, rest = Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
rest[_key - 3] = arguments[_key];
}
var objErr = _propTypes2.default.object.apply(_propTypes2.default, [props, propName, componentName].concat(rest));
if (objErr) {
return objErr;
}
return styleValidator.validate(props[propName], componentName);
}
};
【问题讨论】:
-
style: (props, propName, componentName)这也没有任何意义,在我看来,style应该以function为前缀,以使其符合逻辑 JS。我认为这里遗漏了其他东西,stylebit.. 在第 8698 行说之前是什么? -
@Keith 我在它之前和之后添加了完整的相关代码。
-
啊,对了,这种函数声明直到“ES2015”才出现,所以你需要添加
ES2015babel 预设以在 IE11 上工作。 -
@Keith 我认为 babel-env 可以替代它?
-
是的,确实如此。
env预设应该做到这一点,所以我想知道是否还有另一个.babelrc被使用但没有得到这个。也许您使用的其中一个库没有此设置。如果使用 webpack 是这种情况,您可以覆盖.babelrc设置。
标签: javascript reactjs webpack internet-explorer-11 babeljs