Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add main property to fix importing #159

Closed
wants to merge 1 commit into from
Closed

Add main property to fix importing #159

wants to merge 1 commit into from

Conversation

raimund-schluessler
Copy link

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 #145 (comment). 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 nextcloud/server#28127 (comment)

Signed-off-by: Raimund Schlüßler <raimund.schluessler@mailbox.org>
@raimund-schluessler
Copy link
Author

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 😉. And a single legacy line to make the package work seems acceptable for me.

@sindresorhus
Copy link
Owner

It defines exports, which is a replacement for main.

"exports": "./dist/index.js",

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

@VinceBT
Copy link

VinceBT commented Oct 23, 2022

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants