question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

vite does not handle "browser" field in package.json properly, when using package 'tapable'

See original GitHub issue

Describe the bug

Just install npm package tapable, and import it in main.js

import { SyncHook } from 'tapable';
console.log('load Hook', SyncHook);

Then the console will print an error: image

Then I digged into node_modules/tapable/package.json, and it use browser field for different platforms.

image

and package util is imported in tapable/lib/Hook.js Line 7 image

So In expected result, I will get the file util-browser involved, which described in browser. But actually the pre-bundled code just resolved this into some compatibility code.

image

So how can I solve this?

Reproduction

https://stackblitz.com/edit/vitejs-vite-6grfch?file=main.js

System Info

System:
    OS: macOS 11.4
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 105.61 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.19.0 - ~/.nvm/versions/node/v14.19.0/bin/node
    Yarn: 1.22.17 - ~/.nvm/versions/node/v14.19.0/bin/yarn
    npm: 6.14.16 - ~/.nvm/versions/node/v14.19.0/bin/npm
  Browsers:
    Safari: 14.1.1
  npmPackages:
    @vitejs/plugin-legacy: ^1.7.1 => 1.8.0
    vite: ^2.8.3 => 2.9.1

Used Package Manager

yarn

Logs

No response

Validations

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
zizifncommented, Oct 8, 2022

Does this fix is in "vite": "^3.2.0-beta.0",? if so, I don’t think this is fixed, please check the test repo compare to webpack with more details about the test case. https://github.com/zizifn/vite-browser-test

2reactions
asiaziolacommented, Jul 19, 2022

Hey, similair issue. I’m using dependency which sets couple of modules to false in browser field. However, they are still included in the build

Screenshot 2022-07-19 at 10 31 38 Screenshot 2022-07-19 at 10 30 57
Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting - Vite
Syntax Error / Type Error happens​​ Vite cannot handle and does not support code that only runs on non-strict mode (sloppy mode). This...
Read more >
Changelog - Cypress Documentation
When a chromium based browser tab or process crashes, Cypress will no longer hang indefinitely but will fail the current test and move...
Read more >
Docs • Svelte
Complete documentation for Svelte.
Read more >
module not found fs - You.com | The Search Engine You Control
Module not found: Can't resolve 'fs' in Next.js application ... It sets specific modules to false for use in the browser in package.json....
Read more >
Build a JavaScript library with multiple entry points using Vite3
One of the most crucial steps for having a javascript lib is defining in our package.json how node needs to resolve the files....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found