davidmyersdev / vite-plugin-node-polyfills

A Vite plugin to polyfill Node's Core Modules for browser environments.
MIT License
263 stars 17 forks source link

Failed to resolve import "vite-plugin-node-polyfills/shims/buffer" #81

Open OliverWich opened 4 months ago

OliverWich commented 4 months ago

When using a version higher than 0.17.0, and polyfilling a bunch of stuff (see vite config snippet below), I get the following error: image

The relevant section of my vite config is this:

"plugins": [
// ...
 nodePolyfills({
      globals: {
        Buffer: true,
        global: true,
        process: true,
      },
      include: [
        'fs',
        'path',
        'crypto',
        'stream',
        'util',
        'http',
        'https',
      ],
    }),
// ...
]

With this config everything works fine in 0.17.0 but in the testet versions 0.19.0 and 0.21.0 the error occurs

When trying to include "buffer" in the include array, it also fails because there is no polyfill for it (or it gets already polyfilled by the globals section above). (ERROR: [plugin: node-stdlib-browser-alias] Cannot find module 'vite-plugin-node-polyfills/shims/buffer' from '.')

Upvote & Fund

Fund with Polar

shellscape commented 4 months ago

Just got bit by this one on v0.21.0 @davidmyersdev this is a gnarly regression, could we get a fix in por favor?

FWIW this is due to the class node module resolution not finding anything at vite-plugin-node-polyfills/shims/buffer because the built files exist at vite-plugin-node-polyfills/shims/buffer/dist

raduciobanu22 commented 3 months ago

Similar issue here, version 0.17.0 works though.

choiwonpyo commented 3 months ago

Hello, also, I got same issue. I accepted my senior's comment. just change version to "0.17.0". And it works. Thank you bros.

choiwonpyo commented 3 months ago

Um... Something happens.

I can build with latest version. (not 0.17.0) when I add "vite-plugin-node-polyfills" at the "top-level" of monorepo.

my project status is.

before "vite", I was developing with "cra".

Because I'm amature yet, I can not pick the reason why this situation happens...

Situation

After that experience, I have some test.

I don't know why this solve the problem...

tommymarshall commented 3 months ago

Running into this issue as well -- it occurs from within a lerna repo and a common package is referencing Buffer (but not using vite).

17Amir17 commented 2 months ago

Hello, also, I got same issue. I accepted my senior's comment. just change version to "0.17.0". And it works. Thank you bros.

This

KateAstrid commented 3 weeks ago

Changing the version to 0.17.0 helps me as well. Thank you @raduciobanu22 🙏

davidmyersdev commented 21 hours ago

I wasn't able to reproduce this error with just the config provided above. I'll need a StackBlitz or CodeSandbox example in order to diagnose the issue and get a fix together.