mapbox/concaveman

TypeError: Queue is not a constructor

Closed this issue ยท 16 comments

Hello!

When running version v1.2.0 of concaveman with Webpack (in a vue-cli environment), the following error occurs:

TypeError: Queue is not a constructor
    at findCandidate (index.js:95)
    at concaveman (index.js:65)

In Chrome Debugger, Queue is an object which holds a transpiled ES6 module, and has __esModule and default properties.

Is this a bug in concaveman or my Webpack configuration?

Thanks!

@mbullington, we have same issue after update to v1.2.0:

index.js:95 Uncaught TypeError: Queue is not a constructor
    at findCandidate (index.js:95)
    at concaveman (index.js:65)
    at convex (main.es.js:45)
    at centerOfMass (main.es.js:86)

Points to line var queue = new Queue([], compareDist):

function findCandidate(tree, a, b, c, d, maxDist, segTree) {
    var queue = new Queue([], compareDist);
    // ...
}

It's a known Webpack bug that triggers when a CommonJS package is require-ing a dependency that additionally exposes a module entry point and has a default export. I guess a fix would be to switch to ES bundling for this module too.

At least in the short-term, using webpack-chain we monkey patched tinyqueue like so:

// TODO: Track this issue
// https://github.com/mapbox/concaveman/issues/18
config.resolve.alias.set('tinyqueue', require.resolve('tinyqueue/tinyqueue.js'))

We've caught the issue too. Lost a day of debugging.

I guess a fix would be to switch to ES bundling for this module

Do you mean each client has to do it? Is it possible to fix it once and for everyone to avoid the multiplication of pain (does it really need to export both named and default)?

We manually apply @grassick's fix for now and it works locally but this bug still breaks our build pipelines.

braco commented

I am in contact with Mapbox support about this. The GL JS team is aware but was busy with the v2 release so far.

Thanks for the suggestion @alebinson. I don't want to introduce another 124 dependencies to our project, so we resolve the dependency via a resolutions block in Yarn's package.json. Even better of course if you control the repo yourself.

 "resolutions": {
    "@turf/center-of-mass/concaveman": "https://github.com/grassick/concaveman#patch-1"
  },

Any update on this bug getting resolved? Really appreciate all the work MapBox does for the community.

Hi all, any update on the issue?

I am also facing the same issue, any update on the issue? Thanks.

You can get around this issue by installing tinyqueue as a dependency in your project:

npm install tinyqueue

And then configuring your webpack config with an alias within the resolve object like so:

 resolve: {
        alias: {
            tinyqueue$: require.resolve('tinyqueue/tinyqueue.js')
        }
  },

Hope this helps.

braco commented

@mourner who at Mapbox is responsible for merging the PR fixing this issue? This issue is a year old, and is a big bug that's effecting a lot of users.

Sorry for the late reaction everyone, I was holding back on this because I really don't like the default hack and planned to fully convert this package to a pure ES module with type: "module" instead. Never got around to it but I will at some point. Released v1.2.1 with the fix.

I had this error but with RBush, and using SvelteKit, which uses Vite. It was fixed with the same thing solution as the PR mentioned above.

if (RBush.default) {
    RBush = RBush.default;
}
Zzdl commented

You can get around this issue by installing tinyqueue as a dependency in your project:

npm install tinyqueue

And then configuring your webpack config with an alias within the resolve object like so:

 resolve: {
        alias: {
            tinyqueue$: require.resolve('tinyqueue/tinyqueue.js')
        }
  },

Hope this helps.

You are so great! It is effective,thanks! @JamesLMilner