-
-
Notifications
You must be signed in to change notification settings - Fork 357
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
node: prefix error using in browser #502
Comments
I think version 17 is broken for browser (at least), or server side rendering. |
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. |
Thank you for bringing this issue to our attention. It is clear that ES-Module introduced some issues using file-type in the browser. Although file-type has been primarily written for Node.js, I would personally like to see it can be easily used by the client side community as well. One of the aims of ES-Module is improving interoperability, and here we are, it seems now harder then every before. The dependency on node:Buffer seems to be the challenge. You client side boys and girls always fixed that by polyfilling Node with Webpack. That pollyfilling seems to slowly move to the trashcan, just like CommonJs modules. Modules must specify there own requirement and not rely on pollyfills. I believe what is missing is that file-type does not declare a dependency on node:Buffer. At the same time, for a Node environment, our primary audience, it is not really great to introduce dependencies already overlapping with the Node.js API. I have no magical solution here, I am not super experienced with ES-module, maybe there is a very simple solution. It's an open source project, everyone could pick up this challenge. Looking forward to hear your thoughts. |
@Borewit thanks for your reply. As a workaround, we can install polyfills and import them by webpack directly:
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. |
Thanks for sharing your solution @AaronPorts, that looks like a very reasonable solution to me. I have released strtok3@v7.0.0-alpha.5, which got explicit Buffer imports. If you reinstall |
@Borewit I tried alpha.5 version but have |
You are right, forgot to compile code before publishing, another attempt: 7.0.0-alpha.6 |
I've just checked, strtok3 7.0.0-alpha.6 seems good, but the same issue with Buffer import in token-types 4.1.1 |
Sorry for my late reply. token-types is no ES module yet, and id does not like if I create an explicit import to 'node:Buffer'. |
Update "strtok3" to "^7.0.0-alpha.5". Update "token-types" to "^5.0.0-alpha.0" (first ES module). Resolves: #502
Update "strtok3" to "^7.0.0-alpha.5". Update "token-types" to "^5.0.0-alpha.0" (first ES module). Resolves: #502
@AaronPorts can you let us know if your issue is now resolved? |
@Borewit It seems that |
Missed that one, created Borewit/token-types#396, PR Borewit/token-types#397, fixed in v5.0.0-alpha.2. |
Can this one be closed now @AaronPorts ? |
Sorry for the delay, seems good for me. |
i installed axios as a dependency and this started happening, no idea how to solve it |
Is there a solution for this issue. Seems like it's still broken. i tried one of the code snippets from the readme. The stream method can also be used to read from a remote location:
but looks like its an issue with the imports. Is there a fix for this? |
I modified it to support browsers based on this repo, I hope it can help you: |
but how to use? can you give a example? |
I faced this issue when building my Next.JS application, which uses version Example'use server'; // <<< --- this does the trick
// ... rest of the file |
Current version throws 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. See: sindresorhus/file-type#502 There are ways around by using polyfills, e.g. - https://stackoverflow.com/questions/76500464/issues-while-using-gradio-client-in-next-js/76522223#76522223 - vercel/next.js#33982 but since no functional changes in the detection that impact us have been made, stay back at the old version for now.
I have the same problem when using a Next (14.2.3) component with dynamic import |
Still doesn't work in browsers, when using inside nextjs client components |
Get the following errors when I try to use fileTypeFromBlob in browser:
I can successfully build my project only with
target: "node"
in webpack config. Webpack 5.64.4, file-type 17.0.0.The text was updated successfully, but these errors were encountered: