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: union is not exported, ESM formatting issue? #128

Open
tarngerine opened this issue Sep 22, 2021 · 3 comments
Open

error: union is not exported, ESM formatting issue? #128

tarngerine opened this issue Sep 22, 2021 · 3 comments

Comments

@tarngerine
Copy link

Describe the bug

I'm using https://vitejs.dev, and I'm getting an error during vite build.

import {union} from "polygon-clipping"

error during build:
Error: 'union' is not exported by node_modules/polygon-clipping/dist/polygon-clipping.esm.js, imported by ...

If i do a default import, this works fine:

import polygonClipping from "polygon-clipping"

I have checked the polygon-clipping ESM, it looks fine?

var index = {
  union: union,
  intersection: intersection$1,
  xor: xor,
  difference: difference
};

export default index;

Unsure if this is a Vite or polygon-clipping issue. Thanks!

Reproduction

https://codesandbox.io/s/vite-react-ts-forked-yhl2b?file=/src/App.tsx

Open terminal
Run yarn vite build
See error flagged by the import {union} from "polygon-clipping" line

System Info

System:
    OS: Linux 5.4 Debian GNU/Linux 10 (buster) 10 (buster)
    CPU: (12) x64 Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
    Memory: 5.51 GB / 62.73 GB
    Container: Yes
    Shell: 5.0.3 - /bin/bash
  Binaries:
    Node: 14.17.6 - ~/.nvm/versions/node/v14.17.6/bin/node
    Yarn: 1.22.11 - ~/.nvm/versions/node/v14.17.6/bin/yarn
    npm: 6.14.15 - ~/.nvm/versions/node/v14.17.6/bin/npm
  npmPackages:
    vite: ^2.2.3 => 2.3.3
@tarngerine
Copy link
Author

someone says that the polygon-clipping ESM modules are not properly formatted? vitejs/vite#5035 (comment)

export { union, intersection, xor, difference };

@tarngerine tarngerine changed the title Vite build error: union is not exported error: union is not exported, ESM formatting issue? Sep 22, 2021
@rowanwins
Copy link
Contributor

This is issue with usage - polygon-clipping does not provide named exports so doing this will not work

import {union} from "polygon-clipping"

The library currently only provides a default export so you have to use it like

import polygonClipping from "polygon-clipping"
const union = polygonClipping.union

Hope that helps

@Peque
Copy link

Peque commented Nov 3, 2022

@rowanwins That helped, thanks! 😊

I was also having issues with import { difference } from "polygon-clipping" and with import * as clipping from "polygon-clipping" (and then accessing clipping.difference). import polygonClipping from "polygon-clipping" seems the way to go for now. 👍

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