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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find module 'vite-plugin-node-polyfills/shims/buffer' #74

Closed
shellscape opened this issue Jan 17, 2024 · 9 comments · Fixed by #79
Closed

Cannot find module 'vite-plugin-node-polyfills/shims/buffer' #74

shellscape opened this issue Jan 17, 2024 · 9 comments · Fixed by #79
Labels
bug Something isn't working

Comments

@shellscape
Copy link

Just updates to 0.19.0 from 0.16.0 and started getting the error Cannot find module 'vite-plugin-node-polyfills/shims/buffer

Downgraded back to 0.16.0 and error vanished. Apologies that I don't have the time atm to put together a reproduction, but it seems to affect every vite v4.x project I have going.

@vincesp
Copy link

vincesp commented Jan 18, 2024

I am getting a similar error when upgrading from 0.17.0 to 0.18.0 and later. I am using [email protected].

Error:  Failed to scan for dependencies from entries:
  C:/xxx/frontend/index.html

  X [ERROR] No matching export in "node_modules/vite-plugin-node-polyfills/shims/buffer/dist/index.cjs" for import "Buffer"

    script:C:/xxx/frontend/src/components/renderers/typeHandlers/text/TextEditor.vue?id=0:17:9:
      17 │ import { Buffer } from 'node:buffer'

@davidmyersdev
Copy link
Owner

If either of you could add a reproduction on StackBlitz or similar, that'd be helpful for me to debug.

@davidmyersdev davidmyersdev added the missing reproduction This issue does not provide a reproducible example of the problem. label Jan 20, 2024
@shellscape
Copy link
Author

FWIW it's extremely helpful to have a template ready to go for issues. I've created these two for different projects as a reference: https://stackblitz.com/fork/jsx-email-repro https://stackblitz.com/fork/rollup-repro

I'm not sure how to isolate my use case for this into a repro for Vite, I just don't have enough experience with Vite yet to know how to force the behavior.

@vincesp
Copy link

vincesp commented Jan 22, 2024

Here is the Stackblitz:
https://stackblitz.com/edit/stackblitz-starters-8ajb44?file=package.json

npm run dev:frontend

will yield:

Error:   Failed to scan for dependencies from entries:
  /home/projects/stackblitz-starters-8ajb44/frontend/index.html

  ✘ [ERROR] No matching export in "../node_modules/vite-plugin-node-polyfills/shims/buffer/dist/index.cjs" for import "Buffer"

    script:/home/projects/stackblitz-starters-8ajb44/frontend/src/App.vue?id=0:2:9:
      2 │ import { Buffer } from 'node:buffer'
        ╵          ~~~~~~


    at failureErrorWithLog (/home/projects/stackblitz-starters-8ajb44/node_modules/esbuild/lib/main.js:1641:15)
    at eval (/home/projects/stackblitz-starters-8ajb44/node_modules/esbuild/lib/main.js:1049:25)
    at runOnEndCallbacks (/home/projects/stackblitz-starters-8ajb44/node_modules/esbuild/lib/main.js:1476:45)
    at buildResponseToResult (/home/projects/stackblitz-starters-8ajb44/node_modules/esbuild/lib/main.js:1047:7)
    at eval (/home/projects/stackblitz-starters-8ajb44/node_modules/esbuild/lib/main.js:1059:9)
    at requestCallbacks.on-end (/home/projects/stackblitz-starters-8ajb44/node_modules/esbuild/lib/main.js:1058:54)
    at handleRequest (/home/projects/stackblitz-starters-8ajb44/node_modules/esbuild/lib/main.js:722:17)
    at handleIncomingPacket (/home/projects/stackblitz-starters-8ajb44/node_modules/esbuild/lib/main.js:747:7)
    at Socket.readFromStdout (/home/projects/stackblitz-starters-8ajb44/node_modules/esbuild/lib/main.js:670:7)

With this change, it will work:

npm add -D [email protected] -w frontend
npm run dev:frontend

The error can also be removed by converting the package in the common workspace from "type": "commonjs" to "type": "module" (and changing the export syntax in common/src/index.js).

@shirecoding
Copy link

I have the same issue i have to downgrade to 0.17.0

"vite": "^5.0.3",
"vite-plugin-node-polyfills": "^0.17.0",

@davidmyersdev davidmyersdev added bug Something isn't working and removed missing reproduction This issue does not provide a reproducible example of the problem. labels Feb 8, 2024
@davidmyersdev
Copy link
Owner

This seems to be related to some bigger changes happening in Vite 5. From what I can tell, version v5.0.5 is where things stopped working, although version v5.0.9 is where this specific error started happening. I have an idea for a fix, but I'm still investigating the root cause.

@davidmyersdev
Copy link
Owner

The fix for this has been released in v0.20.0. This fork of the reproduction above is now working with the latest version.
https://stackblitz.com/edit/stackblitz-starters-tkthj2?file=frontend%2Fvite.config.js,frontend%2Fpackage.json

@mfal
Copy link

mfal commented Feb 9, 2024

Unfortunately when upgrading to v0.20.0 the Vite builder errors with

Error: [vite]: Rollup failed to resolve import "vite-plugin-node-polyfills/shims/buffer" from "/dev/test/.yarn/cache/@storybook-addon-interactions-npm-7.6.13-7b19f88dc9-75f04779d1.zip/node_modules/@storybook/addon-interactions/dist/preview.js".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`

@davidmyersdev
Copy link
Owner

@mfal that sounds like a different issue. Can you please open a new issue with a reproduction? I tested the build with the above example, and it seems to be working fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants
@shellscape @davidmyersdev @vincesp @mfal @shirecoding and others