-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
Improve browser compatibility #14
Improve browser compatibility #14
Conversation
@@ -3,7 +3,7 @@ const os = require('os'); | |||
|
|||
const extractPathRegex = /\s+at.*(?:\(|\s)(.*)\)?/; | |||
const pathRegex = /^(?:(?:(?:node|(?:internal\/[\w/]*|.*node_modules\/(?:babel-polyfill|pirates)\/.*)?\w+)\.js:\d+:\d+)|native)/; | |||
const homeDir = os.homedir(); | |||
const homeDir = typeof os.homedir === 'undefined' ? '' : os.homedir(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this a ReferenceError
when os
is not a object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
os
should be an empty object when browser.os = false
in package.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, I see it in https://github.com/defunctzombie/package-browser-field-spec#ignore-a-module. It's rather confusing that the value is to be set to false
instead of something more sane like {}
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could still see it throwing that error for implementations that don't read package.json
, for example when a browser loads the file via <script type="module">
, so I'd advice changing this line to:
os && typeof os.homedir === 'undefined' ? '' : os.homedir();
Fixes #6 as @sindresorhus suggested in #13 (comment)