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

How do I bundle file-type for web browsers? #504

Closed
pastelmind opened this issue Dec 7, 2021 · 1 comment
Closed

How do I bundle file-type for web browsers? #504

pastelmind opened this issue Dec 7, 2021 · 1 comment

Comments

@pastelmind
Copy link

I'm trying to use file-type in a Vite project, but I keep running into errors:

> ../../node_modules/file-type/browser.js:1:21: error: Could not resolve "node:buffer" (mark it as external to exclude it from the bundle)
    1 │ import {Buffer} from 'node:buffer';
      ╵                      ~~~~~~~~~~~~~

 > ../../node_modules/file-type/core.js:1:21: error: Could not resolve "node:buffer" (mark it as external to exclude it from the bundle)
    1 │ import {Buffer} from 'node:buffer';
      ╵                      ~~~~~~~~~~~~~

 > ../../node_modules/file-type/core.js:1489:40: error: Could not resolve "node:stream" (mark it as external to exclude it from the bundle, or add ".catch()" to handle the failure at run-time)
    1489 │   const {default: stream} = await import('node:stream');
         ╵                                          ~~~~~~~~~~~~~

error when starting dev server:
Error: Build failed with 3 errors:
../../node_modules/file-type/browser.js:1:21: error: Could not resolve "node:buffer" (mark it as external to exclude it from the bundle)
../../node_modules/file-type/core.js:1:21: error: Could not resolve "node:buffer" (mark it as external to exclude it from the bundle)
../../node_modules/file-type/core.js:1489:40: error: Could not resolve "node:stream" (mark it as external to exclude it from the bundle, or add ".catch()" to handle the failure at run-time)
    at failureErrorWithLog (/Users/pastelmind/my-project/node_modules/esbuild/lib/main.js:1493:15)
    at /Users/pastelmind/my-project/node_modules/esbuild/lib/main.js:1151:28
    at runOnEndCallbacks (/Users/pastelmind/my-project/node_modules/esbuild/lib/main.js:941:63)
    at buildResponseToResult (/Users/pastelmind/my-project/node_modules/esbuild/lib/main.js:1149:7)
    at /Users/pastelmind/my-project/node_modules/esbuild/lib/main.js:1258:14
    at /Users/pastelmind/my-project/node_modules/esbuild/lib/main.js:629:9
    at handleIncomingPacket (/Users/pastelmind/my-project/node_modules/esbuild/lib/main.js:726:9)
    at Socket.readFromStdout (/Users/pastelmind/my-project/node_modules/esbuild/lib/main.js:596:7)
    at Socket.emit (events.js:400:28)
    at addChunk (internal/streams/readable.js:293:12)

I also tried importing fileTypeFromBuffer(), but ran into the same errors.

How do I bundle this for web browsers using Vite.js?

@Borewit
Copy link
Collaborator

Borewit commented Dec 9, 2021

I think this the same issue as #502, please see my response: #502 (comment)

@Borewit Borewit closed this as completed Dec 17, 2021
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

2 participants