Cannot use as an esm module in nodejs project

Author: StevenDepaCreated Jun 26, 2025Updated Sep 7, 2025

If I create an esm project (es. I put "type": "module" in the package.json), then I do:

bash
node index.js

with an index.js that is simply:

javascript
import flexsearch from "flexsearch";

const d = new flexsearch.Document({});

this results in the error:

(node:10112) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.

I think that the compiled esm file is not correctly recognised as an esm module, I think the solution would be to simply have the file flexsearch\dist\flexsearch.bundle.module.min.js have the .mjs extension (I tried and it works). This should work without messing up with the other type of imports.