Ben
Ben

Reputation: 717

How can I use react-error-overlay outside create-react-app?

I want to use react-error-overlay package from create-react-app outside the create-react-app.

But it doesn't provide any document about how to apply it.

Does anyone know how to make that happened?

Thanks

Upvotes: 3

Views: 3206

Answers (3)

swyx
swyx

Reputation: 2511

hello just leaving a tip - if you want to just use the runtime overlay, do this: https://twitter.com/swyx/status/961413452446257152

you can also synchronously call the buildtime overlay but that is more involved and is best done using the errorOverlayMiddleware (which FYI has moved to react-dev-utils)

good luck

Upvotes: 0

Nick Sarafa
Nick Sarafa

Reputation: 997

Option B - Roll back your react-error-overlay to a 1.x compatible version inside your package.json

Upvotes: 0

Cam Fra
Cam Fra

Reputation: 39

  • Install the react-error-overlay package via npm
  • Add a require.resolve to your app entry point array

    app: [
        require.resolve('react-error-overlay'),
        './src/app/'
    ], 
    
  • Add the setup function to your webpack-dev-server configuration so you can add the middleware

    setup(app) {
        app.use(errorOverlayMiddleware());
    }
    

All done

Upvotes: 3

Related Questions