ProtoDef-io / node-protodef

Describe your protocol, and read it with ease.
MIT License
31 stars 18 forks source link

TypeError: Error.captureStackTrace is not a function in Firefox with Browserify/Webpack #100

Closed Heath123 closed 4 years ago

Heath123 commented 4 years ago

.captureStackTrace is an undocumented V8 function that won't work on other JavaScript engines, which breaks Browserify/Webpack in Firefox (although it works in Chrome). On Edge the error is Object doesn't support property or method 'captureStackTrace'.

This happens here:

class ExtendableError extends Error {
  constructor (message) {
    super(message)
    this.name = this.constructor.name
    this.message = message
    Error.captureStackTrace(this, this.constructor.name)
  }
}
roblabla commented 4 years ago

it should be enough to call this function only if it exists, e.g.

if (Error.captureStackTrace != null)
    Error.captureStackTrace(this, this.constructor.name)

On Firefox (and most other browser), the stack property of Error seems to be created on Error construction and not need to be manually acquired.