sindresorhus / file-type

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

[ERR_REQUIRE_ESM] Error using webpack or babel #611

Closed rafaelgdn closed 11 months ago

rafaelgdn commented 11 months ago

Anyone know how to fix this error?

require() of ES Module /Users/rafaeldecarvalho/dev/bgc/criminal/bgc-scrapers/node_modules/file-type/index.js from /Users/rafaeldecarvalho/dev/bgc/criminal/bgc-scrapers/.webpack/HealthsurveillanceCrawl/src/functions/crawl/healthsurveillance.js not supported.\n' + 'Instead change the require of index.js in /Users/rafaeldecarvalho/dev/bgc/criminal/bgc-scrapers/.webpack/HealthsurveillanceCrawl/src/functions/crawl/healthsurveillance.js to a dynamic import() which is available in all CommonJS modules.

I tried to import in a dynamic way like that: const fileTypeDynamicImport = async () => { const fileType = await import("file-type"); return fileType; };

I tried to add some configs to babel to ignore dynamic import: [ "@babel/preset-env", { "exclude": [ "proposal-dynamic-import" ] } ]

I dont know how to solve this. Any help?

sindresorhus commented 11 months ago

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