javascript - React component require.default undefined -


i've build following component:

import react 'react';  const app = () => (          <div classname="wrapper">             <h1>my app!!!!</h1>         </div>  );  export default app; 

and use react-hot-loader boilerplate as:

import reactdom 'react-dom'; import react 'react'; import { appcontainer } 'react-hot-loader'; import app './component/app/app';  const dest = document.getelementbyid('content');  const render = (component) => {   reactdom.render(     <appcontainer>       <component />     </appcontainer>,     dest   ); };  render(app);  if (module.hot) {     module.hot.accept('./component/app/app', () => {         const nextapp = require('./component/app/app').default; // eslint-disable-line global-require           console.log('=====================================');         console.log(nextapp);         render(nextapp);     }); } 

loading page fine, after updating app component different text, hmr giving error reloading page:

[hmr] connected client.js?6a8d:199 [hmr] bundle rebuilding client.js?6a8d:207 [hmr] bundle rebuilt in 557ms process-update.js:27 [hmr] checking updates on server... client.js:24 ===================================== client.js:25 undefined warning.js:36 warning: react.createelement: type invalid -- expected string (for built-in components) or class/function (for composite components) got: undefined. forgot export component file it's defined in. printwarning @ warning.js:36 warning @ warning.js:60 createelement @ reactelementvalidator.js:171 patchedcreateelement @ patch.dev.js:164 render @ client.js:11 (anonymous) @ client.js:26 hotapply @ bootstrap a9a1805…:566 cb @ process-update.js:52 (anonymous) @ process-update.js:68 process-update.js:115 [hmr] cannot check update (full reload needed) handleerror @ process-update.js:115 applycallback @ process-update.js:45 process-update.js:116 [hmr] invariant violation: element type invalid: expected string (for built-in components) or class/function (for composite components) got: undefined. forgot export component file it's defined in.     @ invariant (http://localhost:3001/dist/main-a9a1805da1160c9fe908.js:946:15)     @ reactcompositecomponentwrapper.instantiatereactcomponent [as _instantiatereactcomponent] (http://localhost:3001/dist/main-a9a1805da1160c9fe908.js:11215:55)     @ reactcompositecomponentwrapper._updaterenderedcomponent (http://localhost:3001/dist/main-a9a1805da1160c9fe908.js:19850:24)     @ reactcompositecomponentwrapper._performcomponentupdate (http://localhost:3001/dist/main-a9a1805da1160c9fe908.js:19813:10)     @ reactcompositecomponentwrapper.updatecomponent (http://localhost:3001/dist/main-a9a1805da1160c9fe908.js:19734:12)     @ reactcompositecomponentwrapper.receivecomponent (http://localhost:3001/dist/main-a9a1805da1160c9fe908.js:19636:10)     @ object.receivecomponent (http://localhost:3001/dist/main-a9a1805da1160c9fe908.js:3479:22)     @ reactcompositecomponentwrapper._updaterenderedcomponent (http://localhost:3001/dist/main-a9a1805da1160c9fe908.js:19843:23)     @ reactcompositecomponentwrapper._performcomponentupdate (http://localhost:3001/dist/main-a9a1805da1160c9fe908.js:19813:10)     @ reactcompositecomponentwrapper.updatecomponent (http://localhost:3001/dist/main-a9a1805da1160c9fe908.js:19734:12) 

as can seen in console log, nextapp returning undefined, render(nextapp) failing.

why const nextapp = require('...').default returning undefined ? how solve issue ?

thanks helping.

are using webpack 2? should not require again. can call render(app) again inside accept callback. see here.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -