file-type: node: prefix error using in browser
Get the following errors when I try to use fileTypeFromBlob in browser:
ERROR in node:buffer
Module build failed: UnhandledSchemeError: Reading from "node:buffer" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
...
ERROR in node:stream
Module build failed: UnhandledSchemeError: Reading from "node:stream" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
...
I can successfully build my project only with target: "node"
in webpack config. Webpack 5.64.4, file-type 17.0.0.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 7
- Comments: 19
Commits related to this issue
- Update strtok3 & token-types for explicit node:buffer imports Update "strtok3" to "^7.0.0-alpha.5". Update "token-types" to "^5.0.0-alpha.0" (first ES module). Resolves: sindresorhus/file-type#502 — committed to sindresorhus/file-type by Borewit 3 years ago
- Update strtok3 & token-types for explicit node:buffer imports Update "strtok3" to "^7.0.0-alpha.5". Update "token-types" to "^5.0.0-alpha.0" (first ES module). Resolves: sindresorhus/file-type#502 — committed to sindresorhus/file-type by Borewit 3 years ago
- Doesn't work for us yet Current version throws Module build failed: UnhandledSchemeError: Reading from "node:buffer" is not handled by plugins (Unhandled scheme). Webpack supports "data:" and... — committed to ente-io/ente by mnvr 2 months ago
I ran into a similar issue using Vite.js and ended up using magic-bytes.js instead. It’s much smaller and doesn’t rely on the Node.js stdlib.
@Borewit thanks for your reply. As a workaround, we can install polyfills and import them by webpack directly:
npm install buffer readable-stream -S
in webpack plugins section:But I’ve got another problem in strtok3 package as it uses Buffer without import. For example when file-type use tokenizer.readToken it results in an error.
I modified it to support browsers based on this repo, I hope it can help you: https://www.npmjs.com/package/file-type-browser
Sorry for the delay, seems good for me.