David
David3mo ago

How to get line number in errors?

Hi, we are currently doing this:
onError: (info) => {
if (isEnv("local")) {
console.error(
`${chalk.bgRed(`${info.error.name}: ${info.error.code}`)} - ${chalk.bgYellow(info.path)}\n${chalk.inverse(info.error.message)} \n`,
)
}
},
onError: (info) => {
if (isEnv("local")) {
console.error(
`${chalk.bgRed(`${info.error.name}: ${info.error.code}`)} - ${chalk.bgYellow(info.path)}\n${chalk.inverse(info.error.message)} \n`,
)
}
},
to get a vague idea of what the error was, but this doesn't really help you with telling on which line it occurred. Is there a way to achieve this? Logging the trace is kind of pointless as they don't point you to your own procedure.
4 Replies
Alex / KATT 🐱
the trace in info.error should work? info.error.stack or whatever if not, it might be that you haven't configured sourcemaps correctly
David
DavidOP3mo ago
Im guessing this must be it then, do you have a reference where this is set up correctly that I can compare to? I do have sourceMap: true in tsconfig.
Alex / KATT 🐱
depends how you compile, here's a webpack version
webpack: (config, options) => {
if (!options.dev) {
config.devtool = options.isServer ? 'eval-source-map' : 'source-map';
}
webpack: (config, options) => {
if (!options.dev) {
config.devtool = options.isServer ? 'eval-source-map' : 'source-map';
}
David
DavidOP3mo ago
Thank you! Im using Turbopack in Next