I can't load through commonjs in Node
See original GitHub issueI tried a number of ways to require it but to no avail, I literally can’t use file-type on Node because of this. It looks like you just need to remove the module prop from the package.json.
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/.../node_modules/file-type/index.js ... Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/.../node_modules/file-type/package.json.
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Node Modules at War: Why CommonJS and ES ... - Code Red
All of the “sibling” scripts in the ES module graph download in parallel, but they execute in order, guaranteed by the loader specification....
Read more >Using ES modules with CommonJS modules in Node.js
Mixing ES modules and CommonJS modules · You can only use import and export in an ES module. Specifically, this means you can...
Read more >node: getting error importing CommonJS module however I try ...
I have a local node module, @em/inVis in my company whose index.d.ts file looks as follows: import UWeb from ".
Read more >CommonJS vs. ES modules in Node.js - LogRocket Blog
Learn about the differences between CommonJS and ES modules when using them in Node.js applications to organize software code.
Read more >How the module system, CommonJS & require works
We can allow Node.js to manage the modules life cycle by using hard coded module loading. It organizes your packages in an intuitive...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Full working example: https://github.com/Borewit/file-type-example/tree/master/commonjs
You are of course free to dislike ESM, but that doesn’t mean it won’t happen.
Dual packages come with their own downsides: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#gistcomment-3850849
I have no plans to switch any of my packages to be dual.