-
-
Notifications
You must be signed in to change notification settings - Fork 27k
[V4] Message formatting is incompatible with Webpack v5 #9880
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
Comments
Fix formatting error on webpack v5, as described here: facebook#9880 Specifically in [this link](https://webpack.js.org/blog/2020-10-10-webpack-5-release/#minor-changes), on the item that says: 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
When I change:
into:
In: Hopefully, it will be fixed soon :-) |
I have the same question.And I can't modify the formatWebpackMessages.js in everyone'node_modules of the team.Please upgrade soon. |
@Lyfme you shouldn't change the module code. Instead, change the input format:
From:
To:
The Hope that helps. |
I have the same question, please upgrade soon! |
For those waiting for the fix to be accepted, you can use a
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 "scripts": {
....
"postinstall": "node tools/postinstall.js",
....
}, |
When we can hope to see getting this resolved. It really easy fix. |
For now, the cleanest workaround hack dirty solution is:
Hoping that #9943 will be merged soon and we will not need this anymore. |
When is it getting fixed. Should I downgrade webpack or react-dev-utils to make it work temporarily and to what version? |
It is causing a real trouble. Please fix it. |
When is it getting fixed? |
Got another workaround without modifying files in node_modules. It changes webpack.stats.toJson() errors and warning arrays from objects to strings. It's a webpack plugin that should be added to the array of plugins in your webpack config // @ts-check
/**
* formatWebpackMessages helper from Create-react-app expects errors and warnings to be
* arrays of strings as they are in Webpack 4.
* Webpack 5 changed them to objects.
* This plugin changes them back to strings until the issue is resolved
* https://github.com/facebook/create-react-app/issues/9880
*/
class FixMessageFormatterPlugin {
/** @type {import('webpack').WebpackPluginFunction} */
apply = compiler => {
compiler.hooks.compilation.tap('FixMessageFormatterPlugin', compilation => {
compilation.hooks.statsFactory.tap('FixMessageFormatterPlugin', stats => {
stats.hooks.result
.for('error')
.tap('FixMessageFormatterPlugin', (obj, data, ctx) =>
formatError(obj, 'ERROR'),
);
stats.hooks.result
.for('warning')
.tap('FixMessageFormatterPlugin', (obj, data, ctx) =>
formatError(obj, 'WARNING'),
);
});
});
};
}
function formatError(obj, prefix = '') {
const moduleName = obj.moduleName;
const location = obj.loc;
if (moduleName) {
prefix = (prefix + ` in ${moduleName}`).trim();
if (location) {
prefix = (prefix + `:${location}`).trim();
}
}
return `${prefix ? prefix + '\n' : ''}${obj.message}`;
}
module.exports = FixMessageFormatterPlugin; |
This issue already closed, but I still encounter it even with the latest version of react-dev-utils.. |
Yes, this is still a problem on version 11.0.4 |
@filipmacek, @darrylsepeda |
Would it also be possible to fix this for version 11.x so as not to introduce the other breaking changes that are a part of version 12.x? My use-case is I'm in a yarn 2 monorepo setup sharing react-dev-utils across workspaces. |
error occurs when webpack throws any error during compilation
Seems like this line should check if
message
is an object with andmessage
key, as webpack v5 mentions in migration guide:Environment
webpack: "5.2.0"
react-dev-utils: "11.0.0"
The text was updated successfully, but these errors were encountered: