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

package.json browsers field is not respected #2802

Closed
fireridlle opened this issue Mar 31, 2021 · 2 comments
Closed

package.json browsers field is not respected #2802

fireridlle opened this issue Mar 31, 2021 · 2 comments

Comments

@fireridlle
Copy link

fireridlle commented Mar 31, 2021

Describe the bug

We are developing a package that is used by our community with vitejs.
In our package.json we have a field browser

  "browser": {
    "http2": false,
    "http": false,
    "https": false,
    "os": false,
    "util": false
  }

So all of these packages are NodeJs packages and we use them only if the code is running by NodeJS.
If code is running by browser, we don't want those packages to be at the final bundle as it increases bundle size.
Webpack respects this field, however, vitejs doesn't.
Is it possible to support this field or did I miss some additional configuration?

Even injected polyfill doesn't work well as it's kind of proxy and doesn't have named imports
original code

import { inspect } from 'util'

build code

import { inspect } from '/@id/__vite-browser-external'

an error

values.js?t=1617178902155:4 Uncaught SyntaxError: The requested module '/@id/__vite-browser-external' does not provide an export named 'inspect'

System Info

 System:
    OS: macOS Mojave 10.14.6
    CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
    Memory: 325.32 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 12.18.0 - ~/.nvm/versions/node/v12.18.0/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.4 - ~/.nvm/versions/node/v12.18.0/bin/npm
  Browsers:
    Chrome: 89.0.4389.90
    Firefox: 80.0.1
    Safari: 14.0.3
  npmPackages:
    @vitejs/plugin-vue: ^1.1.5 => 1.1.5 
    vite: ^2.0.5 => 2.0.5 

Used package manager:
yarn

@fireridlle fireridlle changed the title package.json browsers field package.json browsers field is not respected Mar 31, 2021
@patak-dev
Copy link
Member

@fireridlle this should be fixed with the latest version of Vite, could you try with that one?

@github-actions
Copy link

github-actions bot commented Apr 3, 2021

Hello @fireridlle. Please provide a online reproduction by codesandbox or a minimal GitHub repository. Issues labeled by need reproduction will be closed if no activities in 3 days.

@github-actions github-actions bot closed this as completed Apr 7, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants