rsnext/packages/next/build/webpack/loaders/error-loader.ts
JJ Kasper 6fd2a7fa31
Remove webpack4 types (#39631)
These types are no longer needed as we are only leveraging webpack 5 so this finishes migrating our types away from webpack 4's types.
2022-08-16 09:55:37 +00:00

27 lines
737 B
TypeScript

import chalk from 'next/dist/compiled/chalk'
import path from 'path'
import { webpack } from 'next/dist/compiled/webpack/webpack'
const ErrorLoader: webpack.LoaderDefinitionFunction = function () {
// @ts-ignore exists
const options = this.getOptions() || ({} as any)
const { reason = 'An unknown error has occurred' } = options
// @ts-expect-error
const resource = this._module?.issuer?.resource ?? null
const context = this.rootContext ?? this._compiler?.context
const issuer = resource
? context
? path.relative(context, resource)
: resource
: null
const err = new Error(
reason + (issuer ? `\nLocation: ${chalk.cyan(issuer)}` : '')
)
this.emitError(err)
}
export default ErrorLoader