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

Cloudflare Workers support #595

Closed
Zerebokep opened this issue Apr 6, 2023 · 4 comments
Closed

Cloudflare Workers support #595

Zerebokep opened this issue Apr 6, 2023 · 4 comments

Comments

@Zerebokep
Copy link

It would be great to see cloudflare workers support. Currently it's only possible with version 16.5.4 and node_compat enabled (because of the fs import).

@sindresorhus
Copy link
Owner

We don't plan any special support for Cloudflare Workers. You need to use it through node_compat.

@skyf0l
Copy link

skyf0l commented Mar 7, 2024

Using compatibility_flags = [ "nodejs_compat" ], I got the following error: Error: Dynamic require of "node:events" is not supported with fileTypeFromStream or fileTypeFromBuffer. No idea where this node:events come from...

@skyf0l
Copy link

skyf0l commented Mar 7, 2024

Ok, due to the readable-stream dependency...

@skyf0l
Copy link

skyf0l commented Mar 7, 2024

I've found a workaround for Cloudflare worker, the error is raised by the fileTypeFromStream wrapper using readable-web-to-node-stream (the source of the error) in browser.js.

Simply import the function as follows: import { fileTypeFromBuffer } from "file-type/core"; and hope that the bundler gets rid of this dependency. Of course, you won't be able to use fileTypeFromStream, but fileTypeFromBuffer and fileTypeFromTokenizer are enough.

I hope this solves your problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants