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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly ignore optional deps when bundling vite deps #4223

Merged
merged 1 commit into from Jul 12, 2021

Commits on Jul 12, 2021

  1. fix: correctly ignore optional dependencies when bundling vite deps

    Fixes vitejs#3977
    Fixes vitejs#3850
    
    馃槄 I've accidentally committed the actual fix in vitejs@25d86eb#diff-d17472499351c5bf75d44c67aaa203337dcce321fb578ff05302c61b2b2a3a8aR172
    
    So this PR just removes the erroneous `ingoreDepPlugin`, and moves
    the comments to the `ignore` option of the commonjs plugin.
    
    The cause of the issues is this line: https://github.com/websockets/ws/blob/4c1849a61e773fe0ce016f6eb59bc3877f09aeee/lib/buffer-util.js#L105
    
    When we ignore the optional deps when bundling, we expect
    `require('bufferutil')` to throw an error.
    
    However, with the previous `ignoreDepPlugin` implementation, the
    `require` expression is turned into:
    ```js
    var bufferutil = {
    	__proto__: null
    };
    
    var require$$1 = /*@__PURE__*/getAugmentedNamespace(bufferutil);
    
    // ...
    const bufferUtil = require$$1;
    ```
    No error is throwed, so the code executes into the wrong branch.
    
    After the fix, the `require` expression is left as-is. As `bufferutil`
    is not installed in the user project, the error is thrown as expected.
    sodatea committed Jul 12, 2021
    Copy the full SHA
    7c9eac1 View commit details
    Browse the repository at this point in the history