-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
Failed to resolve import "vite-plugin-node-polyfills/shims/buffer" #81
Comments
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 |
Similar issue here, version 0.17.0 works though. |
Across entire project - Upgrade TypeScript to v5.4.2 - Upgrade Vite to v5 - Upgrade Vite plugins to latest versions (except vite-plugin-node-polyfills) - Upgrade tsup to v8 - Upgrade esbuild to v0.20 - Change tsconfig moduleResolution to "bundler" (Vite 5 compatibility) - vite-config - Replace @esbuild-plugins/node-globals-polyfill, @esbuild-plugins/node-modules-polyfill,rollup-plugin-polyfill-node with vite-plugin-node-polyfills. Pin to v0.17.0 because of davidmyersdev/vite-plugin-node-polyfills#81 - Update vite-plugin-svgr config to handle breaking changes in v4 synapse-react-client - Expose ThemeTypes module augmentation via package.json `exports` - Update storybook-vite config to use same SVGR config apps - Append `?url` to SVG imports used as URLs so they are handled by Vite - Add 'vite/client' types for SVG URL import compatibility with TypeScript
Across entire project - Upgrade TypeScript to v5.4.2 - Upgrade Vite to v5 - Upgrade Vite plugins to latest versions (except vite-plugin-node-polyfills) - Upgrade tsup to v8 - Upgrade esbuild to v0.20 - Change tsconfig moduleResolution to "bundler" (Vite 5 compatibility) - vite-config - Replace @esbuild-plugins/node-globals-polyfill, @esbuild-plugins/node-modules-polyfill,rollup-plugin-polyfill-node with vite-plugin-node-polyfills. Pin to v0.17.0 because of davidmyersdev/vite-plugin-node-polyfills#81 - Update vite-plugin-svgr config to handle breaking changes in v4 synapse-react-client - Expose ThemeTypes module augmentation via package.json `exports` - Update storybook-vite config to use same SVGR config apps - Append `?url` to SVG imports used as URLs so they are handled by Vite - Add 'vite/client' types for SVG URL import compatibility with TypeScript
Across entire project - Upgrade TypeScript to v5.4.2 - Upgrade Vite to v5 - Upgrade Vite plugins to latest versions (except vite-plugin-node-polyfills) - Upgrade tsup to v8 - Upgrade esbuild to v0.20 - Change tsconfig moduleResolution to "bundler" (Vite 5 compatibility) - vite-config - Replace @esbuild-plugins/node-globals-polyfill, @esbuild-plugins/node-modules-polyfill,rollup-plugin-polyfill-node with vite-plugin-node-polyfills. Pin to v0.17.0 because of davidmyersdev/vite-plugin-node-polyfills#81 - Update vite-plugin-svgr config to handle breaking changes in v4 synapse-react-client - Expose ThemeTypes module augmentation via package.json `exports` - Update storybook-vite config to use same SVGR config apps - Append `?url` to SVG imports used as URLs so they are handled by Vite - Add 'vite/client' types for SVG URL import compatibility with TypeScript
Hello, also, I got same issue. I accepted my senior's comment. just change version to "0.17.0". |
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...
|
This also locks vite-plugin-node-polyfills to 0.17.0 until davidmyersdev/vite-plugin-node-polyfills#81 is fixed. It also addresses a vulnerability found via SemGrep in browserify-sign which is a transitive dependency. This was solved by bumping the minor versions of many transitive deps in pnpm-lock.yaml. --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Running into this issue as well -- it occurs from within a lerna repo and a common package is referencing Buffer (but not using vite). |
This |
Changing the version to 0.17.0 helps me as well. Thank you @raduciobanu22 🙏 |
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. |
Happens for me when polyfilling crypto on v0.22.0, and the import comes from the ethers package:
As with others, downgrading to v0.17.0 resolves the issue. |
Same here. Using Quasar/Vite. Needed to go back to version ~0.17.0 |
Going back to v0.17.0 clears the Buffer error, but gives me this:
Also, I would like to note that this error and the Buffer not foun only occur in |
For those of you coming here with a problem with Buffer or any other polyfill, maybe this will help you:
So this will work: plugins: [nodePolyfills(), react(), TanStackRouterVite()], but this won't: plugins: [react(), TanStackRouterVite(), nodePolyfills()], |
We've just updated to 0.22.0 and using I'll close this now, as it is fixed for us, but for some, downgrading to 0.17.0 might still be a valid "fix". |
With Quasar, including the plugin v 0.22 first still does not work. quasar.config.ts {
vitePlugins: [
[nodePolyfills, {include: ['buffer', 'path']}, {server: false}],
// ...
}
|
I was able to fix this by monkey-patching the Vite plugin const nodePolyfillsFix = (options?: PolyfillOptions | undefined): Plugin => {
const origPlugin = nodePolyfills(options)
return {
...origPlugin,
resolveId(this, source: string, importer: (string | undefined), opts: any) {
const m = /^vite-plugin-node-polyfills\/shims\/(buffer|global|process)$/.exec(source)
if (m) {
return `node_modules/vite-plugin-node-polyfills/shims/${m[1]}/dist/index.cjs`
} else {
if (typeof origPlugin.resolveId === 'function') {
return origPlugin.resolveId.call(this, source, importer, opts)
}
}
}
}
} Or more simply because the plugin does not currently define const nodePolyfillsFix = (options?: PolyfillOptions | undefined): Plugin => {
return {
...nodePolyfills(options),
resolveId(source: string) {
const m = /^vite-plugin-node-polyfills\/shims\/(buffer|global|process)$/.exec(source)
if (m) {
return `node_modules/vite-plugin-node-polyfills/shims/${m[1]}/dist/index.cjs`
}
}
}
} |
I still suffer this issue with |
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:
The relevant section of my vite config is this:
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
The text was updated successfully, but these errors were encountered: