Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No esm build, just common js #35

Open
istarkov opened this issue Apr 6, 2022 · 2 comments
Open

No esm build, just common js #35

istarkov opened this issue Apr 6, 2022 · 2 comments

Comments

@istarkov
Copy link

istarkov commented Apr 6, 2022

Thank you, incredibly fast lib.

Without esm build i.e.

"build:esm": "tsc --module es2015 --target es5 --outDir dist/esm"

its impossible to use this library if "type": "module", is set in package.json.
i.e having commonjs I need add .default and this breaks typings

import BTree from 'sorted-btree';
var tree = new BTree.default<number, [number, number]>(undefined, (a, b) => a - b);

To have near zero setup of esm+commonjs support I can recoomend https://github.com/developit/microbundle

@qwertie
Copy link
Owner

qwertie commented Apr 6, 2022

What environment are you running in? I don't have a reason to think that CommonJS modules are broken inside apps that use "type": "module". Node.js documentation just says:

Node.js will treat as CommonJS all other forms of input, such as .js files where the nearest parent package.json file contains no top-level "type" field

Perhaps you can use a workaround like this:

import BTree_ from 'sorted-btree';
const BTree = (BTree_ as any).default as typeof BTree_;

@istarkov
Copy link
Author

istarkov commented Apr 6, 2022

This https://github.com/lukeed/tsm as loader for node i.e. node --loader tsm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants