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

Improve browser compatibility #14

Merged
merged 5 commits into from
Jul 31, 2019

Conversation

Jblew
Copy link
Contributor

@Jblew Jblew commented Jul 30, 2019

Fixes #6 as @sindresorhus suggested in #13 (comment)

@sindresorhus sindresorhus changed the title Enhance browser bundler compatibility: add a hint for bundlers not to load the os module — fixes #6 Improve browser compatibility Jul 31, 2019
@sindresorhus sindresorhus merged commit 0024c67 into sindresorhus:master Jul 31, 2019
@@ -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();
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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 {}.

Copy link
Contributor

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();

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 this pull request may close these issues.

Browser compatibility
3 participants