function formatMessage(message) {
  let lines = message.split(`\n`)

  // Strip Webpack-added headers off errors/warnings
  // https://github.com/webpack/webpack/blob/master/lib/ModuleError.js
  lines = lines.filter(function (line) {
    return !/Module [A-z ]+\(from/.test(line)
  })

  // Remove leading newline
  if (lines.length > 2 && lines[1].trim() === ``) {
    lines.splice(1, 1)
  }

  // Remove duplicated newlines
  lines = lines.filter(function (line, index, arr) {
    return (
      index === 0 || line.trim() !== `` || line.trim() !== arr[index - 1].trim()
    )
  })

  // Clean up the file name
  lines[0] = lines[0].replace(/^(.*) \d+:\d+-\d+$/, `$1`)

  // Cleans up verbose "module not found" messages for files and packages.
  if (lines[1] && lines[1].indexOf(`Module not found: `) === 0) {
    lines = [
      lines[0],
      lines[1]
        .replace(`Error: `, ``)
        .replace(`Module not found: Cannot find file:`, `Cannot find file:`),
    ]
  }

  message = lines.join(`\n`)

  // Clean up syntax errors
  message = message.replace(`SyntaxError:`, friendlySyntaxErrorLabel)

  // Internal stacks are generally useless, so we strip them -
  // except the stacks containing `webpack:`,
  // because they're normally from user code generated by webpack.
  message = message.replace(
    /^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm,
    ``
  ) // at ... ...:x:y
  message = message.replace(
    /^\s*at\s((?!webpack:).)*<anonymous>[\s)]*(\n|$)/gm,
    ``
  ) // at ... <anonymous>
  message = message.replace(/^\s*at\s<anonymous>(\n|$)/gm, ``) // at <anonymous>

  return message.trim()
}
Cleans up Webpack error messages.

This implementation is based on the one from [create-react-app](https://github.com/facebook/create-react-app/blob/edc671eeea6b7d26ac3f1eb2050e50f75cf9ad5d/packages/react-dev-utils/formatWebpackMessages.js).
@param {string} message The raw Webpack error message.
@returns {string} The formatted Webpack error message.