file-type: fileTypeFromFile not found

Description

import { fileTypeFromFile } from 'file-type'

'"file-type"' has no exported member named 'fileTypeFromFile'. Did you mean 'fileTypeFromBlob'?ts(2724)

Existing Issue Check

  • I have searched the existing issues and could not find any related to my problem.

ESM (ECMAScript Module) Requirement Acknowledgment

  • My project is an ESM project and my package.json contains the following entry: "type": "module".

File-Type Scope Acknowledgment

  • I understand that file-type detects binary file types and not text or other formats.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 16

Most upvoted comments

This probably comes down to the fact that the "moduleResolution": "bundler" setting in tsconfig.json (e.g. default in create-next-app setups) instructs TS to not pick up the node conditional export.

Another “solution” would be to add "customConditions": ["node"] to the tsconfig.json, but I suspect this will cause trouble down the line when using modules client-side (in the browser) and suddenly their node exports are being used.

Interestingly, file-type is the first module with which I ran into this problem. Would love to hear about a better fix for this.

Option 1 didn’t work

Weird that the Custom Conditions (option 1) does not work, that is literately the use case provided by the TypeScript documentation, how the Custom Conditions can be used.

But Option 2 worked! Thank you @Borewit !

Great, good to have that confirmed!

Maybe we should just update README?

I agree, I think this is worth mentioning in the README, that if for some reason the import conditions do not work, users can force importing the Node entry point via the subpath.

Good suggestions @soulchild, stating the Node API dependency somehow in Typescript configuration, is in imho the way to go.

Interestingly, file-type is the first module with which I ran into this problem.

Not so many ECMAScript modules have a Node specific entry point defined I guess.