Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Error.captureStackTrace is not a function" in non V8 browser using browser bundle #288

Closed
simonvizzini opened this issue Mar 23, 2022 · 3 comments · Fixed by #289
Closed

Comments

@simonvizzini
Copy link

I'm using the browser bundle of awilix and when I try to resolve something that hasn't been registered it throws a Error.captureStackTrace is not a function error in non V8 browsers, like Firefox and Safari. Works fine in Chromium based browsers.

Problem is that Error.captureStackTrace is a V8 only non-standard function, see here on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#static_methods

It is being used here: https://github.com/jeffijoe/awilix/blob/master/src/errors.ts#L33

Maybe Error.prototype.stack could be used instead? It is also a non-standard property but at least supported by all browsers: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/stack
As far as I understood the stack property should be populated as soon as an Error is thrown.

@jeffijoe
Copy link
Owner

Uh-oh!

I suppose checking if 'captureStackTrace' in Error before using it makes sense? I'd rather have a bad stack trace than blowing up! 😅

@simonvizzini
Copy link
Author

Yeah totally agree it would make sense to check it before using it 😄

@jeffijoe
Copy link
Owner

Fixed and released in v7.0.1 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants