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

Missing error overlay #5452

Closed
1 task
KutnerUri opened this issue Feb 22, 2022 · 0 comments
Closed
1 task

Missing error overlay #5452

KutnerUri opened this issue Feb 22, 2022 · 0 comments
Labels

Comments

@KutnerUri
Copy link
Contributor

KutnerUri commented Feb 22, 2022

When an error occurs during development, Webpack should show an error overlay, similar to Create React App:
Screen Shot 2022-02-22 at 17 52 58

There is an important destination between build (compile) errors, and runtime errors.

Related issues:

Build errors:

Build errors should show just fine, with the built in overlay:
Screen Shot 2022-02-22 at 17 51 46

However, Webpack doesn't read the source files directly. Instead, it is reading the dists, which bit will not output when there is a compilation error. It will show these in the terminal:

So, we need:

  • Create a Bit Webpack plugin to report build errors.

It should be something like this:

const WdsConfig = {
  onBeforeSetupMiddleware(wds) {
    const { app } = wds;
    app.use(bitErrorReporter());
  },
}

Runtime errors:

The default WDS error overlay does NOT handle runtime errors!
Confirmed here - webpack/webpack-dev-server#4308

What's more, since CRA v2 and support for Webpack 5, they seem to rely on this builtin overlay.
We should follow CRA's response to it here - facebook/create-react-app#12014

Possible solutions:

react-refresh-webpack-plugin's overlay

react-refresh-webpack-plugin comes with its own overlay, though it doesn't come with the source file, and objectively looks less good.
Screen Shot 2022-02-22 at 18 16 15

turning it on is as simple as:

new ReactRefreshWebpackPlugin({
  overlay: {
    sockPath: `_hmr/${envId}`,
    // entry: require.resolve('./react-hot-dev-client'),
    // module: require.resolve('./refresh'),
  },
}### react-error-overlay

The previously official react-error-overlay package displayed errors just fine.
This is what we have used, and it's currently not working anymore. (needs investigation)

Using WDS built-in overlay

The built in overlay does not handle runtime errors, though very easy to use:

const wdsConfig = {
  client: {
    overlay: true,
};

Steps to Reproduce

Create any sort of an error, for example:

throw new Error('global runtime error!');

function Cat() {
  throw new Error('runtime error!');

  return <div>Cat component</div>
}
function EmptyComponent() {
  return undefined
}

Build time error are a little more tricky with Bit.

func MalformedComponent() {
  return <div \>hello world</div>
}

Because of bit compilation, it won't make it to the dists.
We'd have to edit it manually:

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Malfromed = void 0;
const react_1 = __importDefault(require("react"));
func Malfromed() { // <---- here
    return react_1.default.createElement("div", null, "hello world");
}
exports.Malfromed = Malfromed;
//# sourceMappingURL=index.js.map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants