geostyler / geostyler-legend

Small library to render map legends with OpenLayers and d3
BSD 2-Clause "Simplified" License
12 stars 9 forks source link

Problem importing LegendRenderer #443

Closed ThierryNormand closed 10 months ago

ThierryNormand commented 12 months ago

Describe the bug When importing the library for an Angular project, I get the error __WEBPACK_IMPORTEDMODULE is not a constructor. To solve this problem, I used the following syntax which worked for a similar problem with OlStyleParser: import { LegendRenderer as MyLegendRenderer } from 'geostyler-legend/dist/LegendRenderer/LegendRenderer'; However, I get the error : Module '"geostyler-legend/dist/LegendRenderer/LegendRenderer"' has no exported member 'LegendRenderer'.

Expected behavior I should not receive an error for the import.

Version

Additional context I found that the declaration of LegendRenderer class has no "export" like OlStyleParser. Adding **export** declare class LegendRenderer{...} solves the problem.

rdewit commented 11 months ago

I have the following in my project (also with geostyler-legend v4.0.0 but vite/React and without Angular), which works fine for me:

import GeostylerLegendRenderer from 'geostyler-legend/dist/LegendRenderer/LegendRenderer'

Just making sure that you have tried using the default export? If so, how did you originally try to import LegendRenderer that gave you the error _ _WEBPACK_IMPORTEDMODULE is not a constructor?

ThierryNormand commented 11 months ago

I tried using the default export, which gave the WEBPACK error. Trying to solve the error as I have done with Geostyler gave me the error stated in my post. As noted in my initial post, I think the LegendRenderer class is missing an export statement.

pelord commented 10 months ago

Any updates?

hwbllmnn commented 10 months ago

I added a named export in #444

hwbllmnn commented 10 months ago

The fix is contained in 4.0.1

ThierryNormand commented 10 months ago

Thank you!