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

FileType.{extensions,mimeTypes} is undefined in browser build #390

Closed
qodeboy opened this issue Sep 10, 2020 · 2 comments
Closed

FileType.{extensions,mimeTypes} is undefined in browser build #390

qodeboy opened this issue Sep 10, 2020 · 2 comments

Comments

@qodeboy
Copy link

qodeboy commented Sep 10, 2020

Hello,

Documentation states that FileType.extensions and FileType.mimeTypes should list corresponding lists. But when accessed from a browser build, both properties are undefined.

Reproducible demo

Consider following code:

import FileType from "file-type/browser";
console.log(FileType, FileType.extensions, FileType.mimeTypes)

It results in following:

GrqM5D9s4DJxgr 1

Here is the demo: https://codesandbox.io/s/charming-edison-7q4p7?file=/src/App.vue

Expected behaviour:

List of supported extensions and mime types are being logged.

@qodeboy
Copy link
Author

qodeboy commented Sep 10, 2020

Ok, sorted it out.

I'm using Nuxt + TypeScript and the thing is initially file-type has been throwing error

This dependency was not found:                                                                                                                                                          
* fs in ./node_modules/strtok3/lib/FsPromise.js

When imported as import FileType from "file-type";. But is appears there is a webpack issue when target is set to node, see https://stackoverflow.com/questions/39249237/node-cannot-find-module-fs-when-using-webpack.

So the solution was to add

node: {
    fs: "empty"
}

To the webpack config and import FileType correctly using import FileType from "file-type";

Cheers!

@qodeboy qodeboy closed this as completed Sep 10, 2020
@Haraldson
Copy link

Haraldson commented Oct 19, 2020

Your ‘solution’ makes it not crash initially, but it will ultimately when trying to use the fromFile in a browser, as fromBlob isn’t available anymore in Node mode. This is no fix in my opinion, and it’s really weird that documented properties aren’t there when using the file-type/browser edition…

I guess what I can do is add node: { fs: 'empty' }, and import selectively from each target, but this API feels super weird.

import FileType from 'file-type/browser'
import { extensions as FileTypeExtensions } from 'file-type'

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