--enable-source-maps


启用 源映射 支持堆栈跟踪。

🌐 Enable Source Map support for stack traces.

当使用像 TypeScript 这样的转译器时,应用抛出的堆栈跟踪会引用转译后的代码,而不是原始源代码位置。--enable-source-maps 启用源映射的缓存,并尽最大努力报告相对于原始源文件的堆栈跟踪。

🌐 When using a transpiler, such as TypeScript, stack traces thrown by an application reference the transpiled code, not the original source position. --enable-source-maps enables caching of Source Maps and makes a best effort to report stack traces relative to the original source file.

重写 Error.prepareStackTrace 可能会阻止 --enable-source-maps 修改堆栈跟踪。在重写函数中调用并返回原始 Error.prepareStackTrace 的结果,以便使用源映射修改堆栈跟踪。

🌐 Overriding Error.prepareStackTrace may prevent --enable-source-maps from modifying the stack trace. Call and return the results of the original Error.prepareStackTrace in the overriding function to modify the stack trace with source maps.

const originalPrepareStackTrace = Error.prepareStackTrace;
Error.prepareStackTrace = (error, trace) => {
  // Modify error and trace and format stack trace with
  // original Error.prepareStackTrace.
  return originalPrepareStackTrace(error, trace);
}; 

注意,启用源映射可能会在访问 Error.stack 时增加应用的延迟。如果你的应用中频繁访问 Error.stack,请考虑 --enable-source-maps 的性能影响。

🌐 Note, enabling source maps can introduce latency to your application when Error.stack is accessed. If you access Error.stack frequently in your application, take into account the performance implications of --enable-source-maps.