我今天刚刚升级到Webpack 2.2并且已经阅读了他们的指南,这些指南似乎仍在进行中.
我在设置我的应用程序以使用webpack-dev-server和热模块重新加载时遇到了困难.
我通过webpack文档关注的指南在这里,但我不得不修改它以使用开发/生产应用程序.
https://webpack.js.org/guides/hmr-react/
我得到的两个错误如下......
Uncaught Error: _registerComponent(...): Target container is not a DOM element. at invariant (eval at(index.js:2), :44:15) at Object._renderNewRootComponent (eval at (index.js:64), :311:44) at Object._renderSubtreeIntoContainer (eval at (index.js:64), :401:32) at render (eval at (index.js:64), :422:23) at hotRenderer (eval at (index.js:73), :41:28) at eval (eval at (index.js:73), :47:5) at eval (eval at (index.js:73), :54:5) at Object. (index.js:73) at e (index.js:1) at Object. (index.js:146)
和
Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object. printWarning @ warning.js?8a56:36 warning @ warning.js?8a56:60 createElement @ ReactElementValidator.js?a599:171 hotRenderer @ index.js?2018:30 (anonymous) @ index.js?2018:35 (anonymous) @ index.js?2018:25 (anonymous) @ index.js:73 e @ index.js:1 (anonymous) @ index.js:146 e @ index.js:1 (anonymous) @ index.js:1 (anonymous) @ index.js:1
我相信问题可能在于我的app文件正在导出一个由Redux Provider组成的组件,其中包含一个React Router Router.
以下是两个罪魁祸首文件:
index.js
import './lib/styles.css' import React from 'react' import { render } from 'react-dom' import App from './App' if (process.env.NODE_ENV === 'development') { const { AppContainer } = require('react-hot-loader') const hotRender = (Component) => { render(, document.getElementById('root') ) } hotRender(App) if (module.hot) { module.hot.accept('./App', () => { const NewApp = require('./App').default hotRender(NewApp) }) } } else { render(App, document.getElementById('app')) }
App.js
import React from 'react' import { Provider } from 'react-redux' import { createStore } from 'redux' import store from './redux/store' import { Router, hashHistory } from 'react-router' import routes from './routes' let s = createStore(store, process.env.NODE_ENV === 'development' ? ( window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() ) : null ) const App = () => () export default App
如果您想检查具有更改的整个PR,那将是非常棒的!代码位于:https://github.com/awitherow/aether/pull/64/files
我为一些滑入PR的CSS更改道歉,但我在这里完成的所有Webpack 2.2及更高版本的升级都是潜在的!
编辑
我尝试了一些修复,简单的修复...但它们没有解决任何问题.
X将应用程序包装在div中,以便它会以某种方式认为它是一个DOM元素.
X将App导出为扩展Component的类
小智.. 7
您使用的是哪个版本的React Router?我也在Warning: React.createElement
控制台中收到 错误,但是从版本切换3.0.2
到4.0.0-alpha.6
预发布版本为我摆脱了它.
您使用的是哪个版本的React Router?我也在Warning: React.createElement
控制台中收到 错误,但是从版本切换3.0.2
到4.0.0-alpha.6
预发布版本为我摆脱了它.