question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[V4] Message formatting is incompatible with Webpack v5

See original GitHub issue
TypeError: message.split is not a function

error occurs when webpack throws any error during compilation

Seems like this line should check if message is an object with and message key, as webpack v5 mentions in migration guide:

Stats json errors and warnings no longer contain strings but objects with information splitted into properties.
MIGRATION: Access the information on the properties. i. e. message

Environment

webpack: “5.2.0” react-dev-utils: “11.0.0”

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:53
  • Comments:15

github_iconTop GitHub Comments

20reactions
femesqcommented, Jan 8, 2021

For those waiting for the fix to be accepted, you can use a postinstall script like this:

  • tools/postinstall.js:
const replace = require('replace-in-file');

const fixFormatWebpackMessages = async () => {
  try {
    const results = await replace({
      files: 'node_modules/react-dev-utils/formatWebpackMessages.js',
      from: `let lines = message.split('\\n');`,
      to: `let lines = [];

  if (typeof message === 'string' || message instanceof String) {
    lines = message.split('\\n');
  } else if ('message' in Object.keys(message)) {
    lines = message['message'].split('\\n');
  }`,
    });

  } catch (e) {
    console.log('error while trying to fix  "formatWebpackMessages.js"', e);
  }
};

fixFormatWebpackMessages();

and on you package.json, add this to the scripts section:

"scripts": {
    ....
    "postinstall": "node tools/postinstall.js",
    ....
  },
11reactions
nlozovancommented, Dec 16, 2020

@Lyfme you shouldn’t change the module code. Instead, change the input format:

const rawMessages = stats.toJson({moduleTrace: false}, true);

From:

const messages = formatWebpackMessages(rawMessages);

To:

const messages = formatWebpackMessages({
   errors: rawMessages.errors.map((e) => e.message),
   warnings: rawMessages.warnings.map((e) => e.message),
 });

The formatWebpackMessages plugin, according to this link, expects an object with 2 props, thus you can push these directly with the expected format.

Hope that helps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

To v5 from v4 - webpack
To v5 from v4. This guide aims to help you migrating to webpack 5 when using webpack directly. If you are using a...
Read more >
Upgrade to Webpack 5 failing - node.js - Stack Overflow
I am attempting upgrade to Webpack 4 to Webpack 5. ... Point sourcemap entries to original disk location (format as URL on Windows) ......
Read more >
Upgrade Guide (v4 -> v5) | Format.JS
Using FormattedMessage without a intl context will fail fast. Why are we doing those changes?​. Rich text formatting callback function is no longer...
Read more >
ts-loader - npm
TypeScript loader for webpack. Latest version: 9.4.2, last published: a month ago. Start using ts-loader in your project by running `npm i ...
Read more >
How to fix the build error of "Error in plugin "webpack-stream" "?
「atl」: Checking finished with 2 errors [21:15:05] 'buildMin' errored after 5.33 s [21:15:05] Error in plugin "webpack-stream" Message: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found