sindresorhus / p-queue

Promise queue with concurrency control
MIT License
3.41k stars 182 forks source link

Add main property to fix importing #159

Closed raimund-schluessler closed 2 years ago

raimund-schluessler commented 2 years ago

If omitted, main defaults to index.js, see https://docs.npmjs.com/cli/v8/configuring-npm/package-json/#main.

Since index.js resides in dist for this repo, omitting the main keyword will make the import fail. This is causing the problems described in https://github.com/sindresorhus/p-queue/issues/145#issuecomment-851873084. With this keyword properly set, importing with

import PQueue from 'p-queue'

instead of

import PQueue from 'p-queue/dist/index'

works again.

cc @skjnldsv @artonge since you had issues with this in https://github.com/nextcloud/server/pull/28127#discussion_r676407842

raimund-schluessler commented 2 years ago

I just saw that you closed a similar PR saying main is not for ES modules.. While this might be true, I think it still makes sense to include this keyword here. For your other packages where index.js is in the root folder, npm simply defaults to index.js if main is not set and everything just works. I think it is alright to have the same behavior here. This would help everyone using this module and prevent you from getting the same issues and PRs all over :wink:. And a single legacy line to make the package work seems acceptable for me.

sindresorhus commented 2 years ago

It defines exports, which is a replacement for main.

https://github.com/sindresorhus/p-queue/blob/35e2d38b6e081475547b3c96d2e8f17f337acbd7/package.json#L9

The problem is with your bundler/build tool, not this package.

VinceBT commented 1 year ago

Having this issue in end of 2022 with the latest tools available, can we reopen this ? Why would this be a problem to add the main as a fallback ?