polygon-clipping icon indicating copy to clipboard operation
polygon-clipping copied to clipboard

error: union is not exported, ESM formatting issue?

Open tarngerine opened this issue 2 years ago • 3 comments

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 avatar Sep 22 '21 17:09 tarngerine

someone says that the polygon-clipping ESM modules are not properly formatted? https://github.com/vitejs/vite/issues/5035#issuecomment-925144257

export { union, intersection, xor, difference };

tarngerine avatar Sep 22 '21 18:09 tarngerine

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

rowanwins avatar Oct 07 '22 03:10 rowanwins

@rowanwins That helped, thanks! :blush:

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. :+1:

Peque avatar Nov 03 '22 19:11 Peque