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

Error "'default' is not exported by <package>" when importing in Svelte file #370

Open
Kcnarf opened this issue Aug 17, 2022 · 4 comments
Open

Comments

@Kcnarf
Copy link

Kcnarf commented Aug 17, 2022

Describe the bug

Hello,
I made and maintain the d3-voronoi-map package (https://github.com/Kcnarf/d3-voronoi-map). Also, I'm not a Svelte user.

An issue (Kcnarf/d3-voronoi-map#16) reports that the d3-voronoi-map package, when imported with Svelte (at least into svelte.dev), raises the error ERROR 'default' is not exported by https://unpkg.com/d3-array@3.2.0/src/index.js, imported by https://unpkg.com/d3-weighted-voronoi@1.1.3/build/d3-weighted-voronoi.js.

I did some explorations (resumed in Kcnarf/d3-voronoi-map#16 (comment)). For short:

  • the error is understandable as the dependency d3-array package has not any default export
  • BUT I don't understand why the error is raised as the source code only import {extent as d3Extent} from d3-array, without any default import.

Thanks for your feedbacks/highlights/comments/help.

PS: the severity of this issue is not appropriate, but don't find any good one.

Reproduction

https://svelte.dev/repl/d3847fb950b54cdca2868aaab2bd7872?version=3.49.0

Logs

from Chrome console:

Error: 'default' is not exported by https://unpkg.com/d3-array@3.2.0/src/index.js, imported by https://unpkg.com/d3-weighted-voronoi@1.1.3/build/d3-weighted-voronoi.js
    at R (index.854e7b3c.js:20:1087)
    at ne.error (index.854e7b3c.js:27:87296)
    at ne.traceVariable (index.854e7b3c.js:27:95377)
    at Ga.findVariable (index.854e7b3c.js:27:39925)
    at xe.bind (index.854e7b3c.js:24:32979)
    at Property.bind (index.854e7b3c.js:24:799)
    at ObjectExpression.bind (index.854e7b3c.js:24:785)
    at VariableDeclarator.bind (index.854e7b3c.js:24:799)
    at Wa.bind (index.854e7b3c.js:24:785)
    at Fa.bind (index.854e7b3c.js:24:785)
Kp @ index.854e7b3c.js:59
await in Kp (async)
(anonymous) @ index.854e7b3c.js:59
setTimeout (async)
(anonymous) @ index.854e7b3c.js:59

System Info

Mac OS Monterey 12.4
Chrome Version 104.0.5112.79 (Build officiel) (x86_64)

Severity

blocking an upgrade

@Conduitry Conduitry transferred this issue from sveltejs/svelte Aug 17, 2022
@Conduitry
Copy link
Member

I'm transferring this to the repo for the REPL.

I haven't really dug into this a ton, but it looks like the code the REPL is getting from your library (https://unpkg.com/d3-weighted-voronoi@1.1.3/build/d3-weighted-voronoi.js) is an UMD built version. The REPL isn't using the ESM version in your package, I'm guessing because you refer to it only as jsnext:main and not as module (https://unpkg.com/d3-weighted-voronoi@1.1.3/package.json).

Neither jsnext:main nor module are official fields in package.json, but the former is older and is mostly deprecated in various tooling in favor of the latter. Exposing pkg.module in your package might help. Updating the REPL to also look at pkg['jsnext:main'] might help. I don't know what might reasonably to done to support loading from the UMD build.

@Kcnarf
Copy link
Author

Kcnarf commented Aug 18, 2022

Thanks for your comment.
I'll definitely dig into that direction.

@benmccann
Copy link
Member

I would recommend changing from umd to esm if you can:

https://github.com/Kcnarf/d3-weighted-voronoi/blob/1d3684d6292ea314b7a07a65506b363d45d83009/rollup.config.js#L11

This FAQ about packaging may also be helpful to you: https://kit.svelte.dev/faq#packages

@Kcnarf
Copy link
Author

Kcnarf commented Aug 19, 2022

@benmccann
thanks for your comment.

I'm currently looking at this cjs/esm/umd and hybrid way of delivering/providing packages.

As the package I'm maintaining is a plugin for the d3.js package/environment (https://d3js.org/, https://github.com/d3/d3), I will follow the same path as d3.js : going from an umd distribution to an esm one (d3/d3#3501). Apparently, this move has been done in mid 2021, and made available in the d3@7.

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

3 participants