Skip to content

Instantly share code, notes, and snippets.

@mucahitgurbuz
Created April 14, 2021 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mucahitgurbuz/3a18d87e763a28a97e872be2943a5820 to your computer and use it in GitHub Desktop.
Save mucahitgurbuz/3a18d87e763a28a97e872be2943a5820 to your computer and use it in GitHub Desktop.
Fix for "TypeError: message.split is not a function" error for Webpack 5
// This is a temporary fix for open issue https://github.com/facebook/create-react-app/issues/9880
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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment