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

Adopt browser field in package.json ala browserify #200

Closed
brianleroux opened this issue Dec 11, 2017 · 4 comments
Closed

Adopt browser field in package.json ala browserify #200

brianleroux opened this issue Dec 11, 2017 · 4 comments

Comments

@brianleroux
Copy link

🙋 feature request

Adopt browser field in package.json ala browserify

🎛 Configurationpackage.json

Per https://github.com/browserify/browserify-handbook#browser-field

{
  "name": "mypkg",
  "version": "1.2.3",
  "main": "main.js",
  "browser": {
    "fs": "level-fs-browser"
  }
}

🤔 Expected Behavior

Clone the browserify feature precisely. This will make SSR much easier to do.

💚 Current Behavior

Current behavior defaults to assuming everything is being bundled for the browser only; allowing devs to opt into specific file cases makes it easier to support prerendering content for the browser.

@devongovett
Copy link
Member

We use browser-resolve which is the same module browserify uses for resolving so it should already work. Is it not for you?

@brianleroux
Copy link
Author

OMG, it does! I had the wrong paths DOH.

So sorry for the noise!

arpith added a commit to arpith/zulip-js that referenced this issue Feb 28, 2018
Some bundlers including Browserify[1] and Parcel[2]
use the browser field in package.json to ignore modules
(using browser-resolve[3]) that do not work well with browsers.
In our case this is the zuliprc related module, fs-readfile-promise.

This commit adds a browser field with fs-readfile-promise set to false
to the package.json, so that clients that are bundled with Browserify
or Parcel can use zulip-js out of the box.

1: https://github.com/browserify/browserify-handbook#browser-field
2: parcel-bundler/parcel#200
3: https://github.com/defunctzombie/node-browser-resolve
aero31aero pushed a commit to zulip/zulip-js that referenced this issue Mar 4, 2018
Some bundlers including Browserify[1] and Parcel[2]
use the browser field in package.json to ignore modules
(using browser-resolve[3]) that do not work well with browsers.
In our case this is the zuliprc related module, fs-readfile-promise.

This commit adds a browser field with fs-readfile-promise set to false
to the package.json, so that clients that are bundled with Browserify
or Parcel can use zulip-js out of the box.

1: https://github.com/browserify/browserify-handbook#browser-field
2: parcel-bundler/parcel#200
3: https://github.com/defunctzombie/node-browser-resolve
@download13
Copy link

I think I might be having a problem with this feature.

I get the following error when trying to run a browser app that depends on Webtorrent.

Uncaught TypeError: net.createServer is not a function
    at new TCPPool (player.js:19968)
    at new WebTorrent (player.js:33083)
    at Object.parcelRequire.1.idb-chunk-store (player.js:33466)
    at newRequire (player.js:48)
    at parcelRequire.4 (player.js:75)
    at player.js:80

Webtorrent includes the node net package as part of TCPPool, which is supposed to be excluded for browser builds.

The package.json file appears to properly set ./lib/tcp-pool.js to false using the browser property.

For some reason it tries to compile in the tcp-pool.js file even though it shouldn't if the import is set to false like it's supposed to be.

Does parcel support using false to disable packages as well as rename them?

@danmarshall
Copy link
Contributor

@devongovett it appears that Parcel is no longer using browser-resolve? I am still experiencing this bug - on Windows. I have a repo demonstrating the bug.

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

No branches or pull requests

4 participants