flauwekeul / honeycomb

Create hex grids easily, in node or the browser.
https://abbekeultjes.nl/honeycomb
MIT License
630 stars 57 forks source link

Unexpected token #97

Closed Perlkonig closed 1 year ago

Perlkonig commented 1 year ago

I have a React app that was building and working fine. I upgraded to Honeycomb 4 and updated all my code to the new API, and my tests run fine, but when I try to build my actual app, I get the following error:

./node_modules/honeycomb-grid/dist/honeycomb-grid.mjs 171:3
Module parse failed: Unexpected token (171:3)
File was processed with these loaders:
 * ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|     return -this.q - this.r;
|   }
>   q;
|   r;
|   constructor() {

That line number corresponds to the throw in the following code:

function nt(r, t) {
  if (S(r) && S(t))
    return r.col === t.col && r.row === t.row;
  if (Object.hasOwn(r, "col") || Object.hasOwn(t, "col"))
    throw new Error(
      `Can't compare coordinates where one are offset coordinates. Either pass two offset coordinates or two axial/cube coordinates. Received: ${JSON.stringify(
        r
      )} and ${JSON.stringify(t)}`
    );
  const e = H(r) ? E(r) : r, n = H(t) ? E(t) : t;
  return e.q === n.q && e.r === n.r;
}

I'm tearing my hair out trying to figure out why this is happening. It's React + Webpack + Babel. Any insight would be appreciated. Thanks!

flauwekeul commented 1 year ago

The line number (171) corresponds to that line, but the column number (3) does not. Also, I wouldn't know why that line would have an unexpected token.

Maybe your project config expects dependencies to be in commonjs (module.exports = {}) syntax while Honeycomb v4 uses native module syntax (export {}). Maybe this helps?

Could you make a reproduction of the problem on stackblitz or something similar?

Perlkonig commented 1 year ago

Thanks for this. I will see what I can do with this, and if doesn't lead anywhere, I'll see if I can create an isolated reproduction. I appreciate the response.

Perlkonig commented 1 year ago

Closing as this is definitely not a "you" issue. Again, I appreciate the response.