KusStar / vite-bundle-visualizer

CLI for visualizing your vite project bundle.
MIT License
321 stars 7 forks source link

v1.0.0 fails in Yarn projects with Plug'n'Play #15

Open bitjson opened 9 months ago

bitjson commented 9 months ago

Following this commit, Yarn projects with Plug'n'Play no longer works (version 0.11.0 worked so long as the project set yarn unplug vite-bundle-visualizer).

The error after upgrading to 1.0.0:

❯ yarn vite-bundle-visualizer
file:///...project.../.yarn/cache/import-from-esm-npm-1.3.3-4c64f297d5-4287ff7e7b.zip/node_modules/import-from-esm/index.js:100
        const error = new Error(errorString);
                      ^

Error: Cannot find module 'vite'
    at importFrom (file:///...project.../.yarn/cache/import-from-esm-npm-1.3.3-4c64f297d5-4287ff7e7b.zip/node_modules/import-from-esm/index.js:100:17)
    at async start (file:///...project.../.yarn/cache/vite-bundle-visualizer-npm-1.0.0-aad67201df-9113c78bf4.zip/node_modules/vite-bundle-visualizer/index.js:25:21)
    at async file:///...project.../.yarn/cache/vite-bundle-visualizer-npm-1.0.0-aad67201df-9113c78bf4.zip/node_modules/vite-bundle-visualizer/bin.js:35:1 {
  code: 'MODULE_NOT_FOUND'
}

Node.js v20.11.0
KusStar commented 9 months ago

Could you please supply a demo project with Yarn PnP?

Additionally, what Yarn version are you using? Maybe some version of Yarn PnP don't support ESM.

bitjson commented 9 months ago

Thanks for looking into it @KusStar!

Here's a project where v0.11.0 works but v1.0.0 fails. It's using the latest stable yarn@4.0.2.

nix6839 commented 9 months ago

It seems to be related to these issues: https://github.com/sheerlox/import-from-esm/issues/80 -> https://github.com/wooorm/import-meta-resolve/issues/10

KusStar commented 9 months ago

It seems to be related to these issues: sheerlox/import-from-esm#80 -> wooorm/import-meta-resolve#10

Thanks for pointing out the solution, but the import-from-esm@1.4.0-alpha.1 is unstable, so maybe it was not a good fix now.

> [!CAUTION]
> In this alpha version, we are using the built-in `import.meta.resolve` function. It is still behind an experimental flag until Node v20.6.0, and as of v21.6.0, its `parentURL` parameter is still flagged. Hence, for this version of the library to work correctly, you _must_ run Node with the `--experimental-import-meta-resolve` flag.

Just use vite-bundle-visualizer@0.11.0 for now.

nix6839 commented 7 months ago

It currently only works in a limited way, installing and using it in your project via yarn add -D vite-bundle-visualizer, yarn vite-bundle-visualizer.

Contrary to expectations, yarn dlx vite-bundle-visualizer is not working. However, #18 does resolve the yarn vite-bundle-visualizer issue reported by the original issue reporter.

It only works in a limited way, so we'll need to reopen the issue.