This pull request fixes a blocker issue when trying to use this module as a "module" (ESM).
Tested on Node.js 14, 16, 18, 20 with require('@flatten-js/interval-tree') and import.
You can verify the fix via my temporary fork: @noomorph/interval-tree.
Problem
Expected:
import IntervalTree from '@flatten-js/interval-tree';
typeof IntervalTree // function
Actual:
import IntervalTree from '@flatten-js/interval-tree';
typeof IntervalTree // object š„
Reason
In fact, this line in your package.json doesn't work:
"module": "dist/main.esm.js",
You can easily check that by deleting that file, and import IntervalTree from '@flatten-js/interval-tree'; will still work because it never looked there, to start with ā it always uses the CommonJS version.
So the fix is to add exports section which Node.js really recognizes:
I had to rename esm.js to .mjs because Node.js doesn't tolerate other extensions, e.g.:
> await import('@flatten-js/interval-tree')
(node:58606) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
Thanks in advance for looking! I hope you and your family are safe.
This pull request fixes a blocker issue when trying to use this module as a "module" (ESM).
Tested on Node.js 14, 16, 18, 20 with
require('@flatten-js/interval-tree')
andimport
.You can verify the fix via my temporary fork:
@noomorph/interval-tree
.Problem
Expected:
Actual:
Reason
In fact, this line in your
package.json
doesn't work:You can easily check that by deleting that file, and
import IntervalTree from '@flatten-js/interval-tree';
will still work because it never looked there, to start with ā it always uses the CommonJS version.So the fix is to add
exports
section which Node.js really recognizes:I had to rename
esm.js
to.mjs
because Node.js doesn't tolerate other extensions, e.g.:Thanks in advance for looking! I hope you and your family are safe.