polygon-clipping
polygon-clipping copied to clipboard
error: union is not exported, ESM formatting issue?
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
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 };
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 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: