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.jsoncontains 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
This probably comes down to the fact that the
"moduleResolution": "bundler"setting intsconfig.json(e.g. default in create-next-app setups) instructs TS to not pick up thenodeconditional export.Another “solution” would be to add
"customConditions": ["node"]to thetsconfig.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-typeis the first module with which I ran into this problem. Would love to hear about a better fix for this.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.
Great, good to have that confirmed!
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.
Not so many ECMAScript modules have a Node specific entry point defined I guess.