rocicorp / fractional-indexing

Fractional Indexing in JavaScript
https://npmjs.com/fractional-indexing
Creative Commons Zero v1.0 Universal
305 stars 23 forks source link

Add "main" to package.json #8

Closed tslocke closed 2 years ago

tslocke commented 2 years ago

Was unable to import this as a module in a Jest environment without this.

arv commented 2 years ago

What version of node/npm/jest are you using?

main is only for legacy versions of node.

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

tslocke commented 2 years ago

Jest 27.5.1, Node 16.14.2, npm 8.5.0

Weird. I have no idea why I'm getting this error then. Lots of other imports with no problem.

Could the target/module settings in tsconfig be relevant? I have:

    "target": "ESNext",
    "module": "ESNext",
    "moduleResolution": "node",
arv commented 2 years ago

Those versions all look good. Let me try...

https://gist.github.com/arv/0a3f7b5c0b831f15b5eaaea7a5e5a725

tslocke commented 2 years ago

I don't have "type": "module" in my package.json. Is that the issue?

If I add it, I get errors loading jest.config.js and babel.config.js

You appear to be using a native ECMAScript module configuration file, which is only supported when running Babel asynchronously.

arv commented 2 years ago

If you add "type": "module" you probably need to rename some of your config files to ".cjs".

tslocke commented 2 years ago

Is there a downside to accepting the PR? Maybe there is, but if not it seems like it could be helpful for people stuck between the two module systems like I seem to be.

arv commented 2 years ago

No downside. Just trying to understand.