flauwekeul / honeycomb

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

"export 'FlatCompassDirection' was not found in 'honeycomb-grid' #52

Closed guillaume-alvarez closed 4 years ago

guillaume-alvarez commented 4 years ago

Hi,

I'm using this (very useful) library with typescript and webpack and run into this warning

"export 'FlatCompassDirection' was not found in 'honeycomb-grid'

for this code

import { Hex, Point, FlatCompassDirection } from 'honeycomb-grid';
...
const neighbors = grid.neighborsOf(hex, [
        FlatCompassDirection.SE, FlatCompassDirection.S, FlatCompassDirection.SW,
        FlatCompassDirection.NW, FlatCompassDirection.N, FlatCompassDirection.NE,
]);

It results in this error at runtime:

TypeError: honeycomb_grid__WEBPACK_IMPORTED_MODULE_14__.FlatCompassDirection is undefined

It looks a lot like this webpack issue, that seem to indicate you can fix the issue by changing the way it is declared.

Many answers on stackoverflow seem to imply it could also work by declaring the enum as 'const' in the types declaration file.

flauwekeul commented 4 years ago

Would this solve your issue:

import type { Hex, Point, FlatCompassDirection } from 'honeycomb-grid';

Source: https://github.com/webpack/webpack/issues/7378#issuecomment-605685470

guillaume-alvarez commented 4 years ago

Not, because the issue here is that the value is not imported. :-(

flauwekeul commented 4 years ago

that seem to indicate you can fix the issue by changing the way it is declared

Can you point me to an example of that? And can you also supply an example of:

Many answers on stackoverflow seem to imply it could also work by declaring the enum as 'const' in the types declaration file

guillaume-alvarez commented 4 years ago

https://stackoverflow.com/questions/50564756/exporting-enum-from-typescript-type-definition-file https://stackoverflow.com/questions/50670145/typescript-does-not-recognize-exported-enum

flauwekeul commented 4 years ago

Ok, could you test if this solves your issue (by replacing the existing enum in your local honeycomb.d.ts with this):

export const enum FlatCompassDirection {
  SE = 'SE',
  S = 'S',
  SW = 'SW',
  NW = 'NW',
  N = 'N',
  NE = 'NE',
}
guillaume-alvarez commented 4 years ago

Sure I can (I did not think you could touch theses files).

It solves the issue!

flauwekeul commented 4 years ago

You can change those files, but they'll be overridden when you run npm install (and there's a change in the file).

Anyway, great! I'll publish a new version later today.

flauwekeul commented 4 years ago

Fixed in 3.1.7

Please let me know if you have any more questions.