Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

instructions for adding react-error-overlay? #2890

Closed
tsiq-swyx opened this issue Jan 31, 2018 · 7 comments
Closed

instructions for adding react-error-overlay? #2890

tsiq-swyx opened this issue Jan 31, 2018 · 7 comments

Comments

@tsiq-swyx
Copy link
Contributor

tsiq-swyx commented Jan 31, 2018

Issue details

Hi friends! i would like to add react-error-overlay to my storybook webpack.config.js but i dont know how... any help would be appreciated!

Steps to reproduce

what i have so far:

in .storybook/webpack.config.js:

module.exports = {
  plugins: [
    // your custom plugins
  ],
  entry: [
    require.resolve('react-error-overlay') // https://github.com/facebook/create-react-app/issues/2344
  ],
  module: {
    rules: [
      // add your custom rules.
    ],
  },
};

and in .storybook/middleware.js:

const errorOverlayMiddleware = require('react-dev-utils/errorOverlayMiddleware');

// this works
// module.exports = function(app) {
//   app.use(errorOverlayMiddleware())
// }

//this also works
module.exports = errorOverlayMiddleware;

and storybook runs fine but it doesnt catch the error and render the ErrorOverlay iframe.

Please specify which version of Storybook and optionally any affected addons that you're running

"webpack": "^3.10.0",
"@storybook/react": "^3.3.11",
"@storybook/addon-actions": "^3.3.11",
"@storybook/addon-links": "^3.3.11",
"@storybook/addons": "^3.3.11",

please let me know your ideas and i would be happy to try them out!

@ndelangen
Copy link
Member

There's some info / discussion on this here: #1088

@tsiq-swyx
Copy link
Contributor Author

tsiq-swyx commented Jan 31, 2018

after looking at how create-react-app now does things i am not confident that react-error-overlay is all that is needed for this stuff. do we need webpackHotDevClient? when i tried implementing just react-error-overlay, nothing happened when i intentionally threw an error on my storybook. it seems that webpackHotDevClient reexports ErrorOverlay anyway so it looks like i just need to make that work. Now i have no idea how to configure webpackHotDevClient as just adding it to my webpack.config.js doesn't do anything.

@Hypnosphi
Copy link
Member

Hypnosphi commented Jan 31, 2018

Note that you can't modify entry point in custom webpack config. You may want to add something like this at the top of your config.js instead:

if (process.env.NODE_ENV !== 'production') {
  require('react-error-overlay');
}

@Hypnosphi
Copy link
Member

As for middleware, we have a non-documented (unfortunately) feature of adding it using middleware.js file in config dir:

const errorOverlayMiddleware = require('react-error-overlay/middleware')

module.exports = router => router.use(errorOverlayMiddleware())

@tsiq-swyx
Copy link
Contributor Author

well whaddaya know!!!!

image

config.js:

import { configure } from '@storybook/react';
if (process.env.NODE_ENV !== 'production') {
  require('react-error-overlay');
  require('react-dev-utils/webpackHotDevClient')
}

// automatically import all files ending in *.stories.js
const req = require.context('../stories', true, /.stories.js$/);
function loadStories() {
  req.keys().forEach((filename) => req(filename));
}

configure(loadStories, module);

middleware.js:

const errorOverlayMiddleware = require('react-dev-utils/errorOverlayMiddleware');

module.exports = router => router.use(errorOverlayMiddleware())

@tsiq-swyx
Copy link
Contributor Author

thanks so much for your help guys! you're amazing. same day issue solving. wow.

@ChristopherHButler
Copy link

@tsiq-swyx any idea how I could use this with an iFrame inside a react app? I am making an app similar to codesandbox and I would like to show this when there is a runtime error or bundling error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants