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

dist not commonjs compatible #137

Closed
kumavis opened this issue Nov 2, 2020 · 17 comments
Closed

dist not commonjs compatible #137

kumavis opened this issue Nov 2, 2020 · 17 comments

Comments

@kumavis
Copy link

kumavis commented Nov 2, 2020

dist contains export statement here https://github.com/Pomax/bezierjs/blob/master/dist/bezier.js#L2236

possibly a mistake? it is possible to build "hybrid packages" that are compatible with both esm and commjs

related vasturiano/force-graph#152

@Niek
Copy link

Niek commented Nov 2, 2020

Same problem here, can't update to 3.x until this is fixed

@Pomax
Copy link
Owner

Pomax commented Nov 2, 2020

@Niek: note that nothing is "broken", and so doesn't need a "fix": this is an enhancement request. The new library was explicitly released as an ES module because everything has had support for ES modules for several versions now (all modern browsers have supported them for many, many versions, and Node's supported them for four versions, the latest 2 of which are native rather than through a runtime flag).

@kumavis if you can let me know how to make hybrid packages that work, I can look at whether that's something that can easily be added here (as far as I know the import and export keywords are illegal outside of ES module context, which is why hybrid packages weren't an option before).

@Niek
Copy link

Niek commented Nov 2, 2020

@Pomax sorry if my comment sounded too harsh. ES is definitely the way to go, but there seems to be some issue with the package being identified as CJS. I'm trying to get v3 working with https://github.com/Xetera/ghost-cursor (typescript, importing this module) but it fails with:

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: node_modules/bezier-js/dist/bezier.js
require() of ES modules is not supported.
require() of node_modules/bezier-js/dist/bezier.js from lib/math.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename bezier.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from node_modules/bezier-js/package.json.

@danmarshall
Copy link

Hi @Niek, the new bezier-js V3 is a breaking change from v2 from the TypeScript typings. So if you’re using TypeScript, you may want to keep using v2 until someone writes typings for v3.

@Pomax
Copy link
Owner

Pomax commented Nov 2, 2020

Ahh, yes if we're talking about typescript, that's a kettle of fish I've no experience with.

Having said that: you should not be using dist/bezier.js if you're using it as a normal dependency, as the dist copy only exists to make it easy for folks to copy a single file into whatever static asset dir they have set up for their website. For anything with build steps, you'll want to use the normal entry point that's indicated by package.json.

@kumavis
Copy link
Author

kumavis commented Nov 3, 2020

Having said that: you should not be using dist/bezier.js if you're using it as a normal dependency, [...]. For anything with build steps, you'll want to use the normal entry point that's indicated by package.json.

dist/bezier.js is the entry point indicated in the package.json

"main": "./dist/bezier.js",

@Pomax
Copy link
Owner

Pomax commented Nov 3, 2020

hm, let's see what happened there.

@Pomax
Copy link
Owner

Pomax commented Nov 3, 2020

Right, well: I have no idea why lib and dist were reversed, but dist should have been in the npmignore, not lib, and the main entry point should have been lib/bezier.js, not dist/bezier.js...

Thanks for pointing this out, I've updated both files and pushed a v3.1.0 to NPM with those changes

@baughmann
Copy link

Is this not typescript compatible quite yet?

@Pomax
Copy link
Owner

Pomax commented Nov 14, 2021

Depends on what you mean with "compatible"? TS is a superset of JS, so all JS is by definition TS compatible. If you mean "still doesn't have typing": no, because I write plain JS, not TS.

@Pomax
Copy link
Owner

Pomax commented Nov 14, 2021

closing this, since a version with fix was pushed out quite a while ago.

@Pomax Pomax closed this as completed Nov 14, 2021
@baughmann
Copy link

closing this, since a version with fix was pushed out quite a while ago.

The typings are out of date. Not your fault, like you said. But on top of that I get a “Bezier not exported from bezier-js”, even when just declaring the module in my index.d.ts

No worries though, as I ended up just copying the functionality I needed and rewriting it a bit locally in my project and adding types.

Thank you for the awesome library btw!

@Pomax
Copy link
Owner

Pomax commented Nov 14, 2021

If the library doesn't work as a normal JS import, that's 100% a bug and if you can file a bug with STR for that, that'd be appreciated.

@baughmann
Copy link

@Pomax Gotcha, thank you. Maybe at some later time. However, my immediate needs are taken care of and fixing this bug will not assist me in my own project at this time. At some later point in the project, I may wish to switch back to the full lib. At that point I will assist in identifying/fixing the possible bug and updating/maintaining the typings.

@Pomax
Copy link
Owner

Pomax commented Nov 14, 2021

you don't need to fix it. I just need to have an issue for it so it's known and someone (probably me) can fix it. Because this is open source: if you know there's a problem, then at least report it, not "for your benefit", but "for everyone's benefit" =)

@baughmann
Copy link

baughmann commented Nov 14, 2021

@Pomax I very well could just be doing something dumb (i.e., a bad TS config or something). I'll try to upload a minimal reproducible codebase sometime today or tomorrow and create a ticket.

I didn't do anything crazy, standard create-react-app typescript template. Since the last release was April, if I wasn't doing something dumb I'd assume someone would have caught it by now.

@baughmann
Copy link

@Pomax Please see #164

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

Successfully merging a pull request may close this issue.

5 participants