sindresorhus / file-type

Detect the file type of a file, stream, or data
MIT License
3.64k stars 345 forks source link

Add support for ES module "require" syntax #634

Closed JRiggles closed 2 months ago

JRiggles commented 2 months ago

When trying to include file-types using require syntax

const fileType = require('file-type');

it fails with the following error:

ReferenceError: require is not defined in ES module scope, you can use import instead

I'm working on an existing codebase that uses require, so I can't easily work with

import { fileTypeFromFile } from 'file-type';

Any help / advice is welcome!

sindresorhus commented 2 months ago

https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

JRiggles commented 2 months ago

Heard, thanks Sindre! I'll see what I can figure out.