我正在开展一个反应项目,最近我们要求它必须支持Google Chrome版本34.为了让它显示,我必须将反应版本从16.0.0降低到15.6.2。我试图解决一个错误,但我不确定它来自哪里。它起源于webpack包。
decoderReactBundle.js:5 Uncaught ReferenceError: window is not defined
该行是:
var parentHotUpdateCallback = window["webpackHotUpdate"];
如果我将反应版本移回16.0.0,则错误会消失,一切都很好,但不会在Chrome 34中显示。
这是我的package.json文件。我想我必须调整其中一个依赖项的版本,但我不确定哪一个。
{
"name": "ava",
"version": "0.1.0",
"private": true,
"main": "app.js",
"dependencies": {
"broadwayjs": "0.0.2",
"query-string": "^5.0.1",
"react": "^15.6.2",
"react-dom": "^15.6.2",
"react-google-maps": "^9.2.2",
"react-scripts": "1.0.14",
"react16-spinjs": "^3.0.1",
"underscore": "^1.8.3",
"html-webpack-plugin": "^2.30.1"
},
"scripts": {
"start": "webpack-dev-server --open",
"dev": "webpack -d --watch",
"build": "react-scripts build webpack",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-plugin-syntax-object-rest-spread": "^6.13.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"webpack": "^3.9.1",
"webpack-dev-server": "^2.9.7"
}
}
答案 0 :(得分:0)
嗯,您可以尝试使用Webpack ProvidePlugin在构建中为window
设置引用:
new webpack.ProvidePlugin({
'window': window
})
任何时候Webpack都会看到对window
的引用,它应该在构建时用窗口实例替换。