perliedman / geojson-path-finder

Find shortest path through a network of GeoJSON
https://www.liedman.net/geojson-path-finder/
ISC License
300 stars 86 forks source link

"Queue is not a constructor" error when bundled with WebPack #71

Closed soryy708 closed 3 years ago

soryy708 commented 3 years ago

If I bundle using Webpack and I import this library, when I call findPath on an instance of PathFinder I get the following error:

Queue is not a constructor

in the dijkstra.js file

soryy708 commented 3 years ago

I found a workaround: https://github.com/mourner/rbush-knn/issues/18#issuecomment-616130211

Add this to the Webpack config:

resolve: {
    alias: {
      "tinyqueue": path.join(__dirname, 'node_modules', 'tinyqueue', 'tinyqueue.js')
    }
  }
perliedman commented 3 years ago

Nice! I think this issue comes up a lot when mixing Webpack with CommonJS and ESM. From my understanding, it's really hard to fix on the module author side, so I think your workaround is the best I've seen so far!

I'm closing this, since it seems resolved, but can open again if there's something more that can be done on the module side!