sindresorhus / p-queue

Promise queue with concurrency control
MIT License
3.47k stars 185 forks source link

Module not found: Error: Can't resolve 'p-queue' after updating to 7.1.0 #145

Closed rakhadkz closed 3 years ago

rakhadkz commented 3 years ago

6.6.2 => 7.1.0 I've found a pretty similar issue title before, but that one was related to react-scripts start command It works with the previous Major version. I moved to ESM (replaced requied() to import). Any ideas?

node version 14.x p-queue 7.1.0

using webpack-dev-server (^3.11.1)

sindresorhus commented 3 years ago

This is not the place to ask for support regarding Webpack or webpack-dev-server. This package works fine with plain Node.js. I would open an issue on Webpack or webpack-dev-server asking for help there.

CristoMonte commented 3 years ago

I have the same problem with parcel on version 7.1.0, but it works fine with version 6.6.2.

sanwar-oc commented 3 years ago

I also have the same problem with 7.1.0 with webpack build. I'm downgrading to 6.6.2.

bjornlll commented 3 years ago

I had the same issue with an expo init-generated React Native app (using Facebook's Metro Bundler, not webpack).

Thanks for the tip! Downgrading to 6.6.2 solved it for me.

skjnldsv commented 3 years ago

@sindresorhus this is an issue with this lib. Importing with import PQueue from 'p-queue' just fails. Webpack cannot find your export path (latest webpack5, using tons of other esm import and they all work fine)

JamesGarbaczewski commented 3 years ago

Ran into the same issue. Importing import PQueue from 'p-queue/dist'; worked

tlgimenes commented 3 years ago

I'm having the same problem in here and I think this isn't a problem with this library. I think, however, for compatibility reasons, a "module" field is missing on this lib's package.json so tools like tsdx (that uses rollup) can work fine.

okbeng03 commented 3 years ago

Ran into the same issue. Importing import PQueue from 'p-queue/dist'; worked

The error maybe package not export main entry point

I'm try local, add the main define , it works

kitsunde commented 1 year ago

It indeed runs just fine with plain javascript.

Another issue is that it confuses eslint-plugin-import on import/no-unresolved. Which does resolve when it's p-queue/dist however .esm won't import on that.

This isn't the case with p-all, p-map, or p-throttle, not sure what's different in this module, but my project is only partially esm and it's only maintained for pure esm projects.

mifi commented 1 year ago

Doing some research, it seems that p-queue is different from Sindre's other p-* modules in that p-queue has a build step and exports ./dist/index.js:

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

Meanwhile the other packages don't have a build step but instead "exports": "./index.js", directly:

I'm guessing that webpack and other bundlers, when they don't find a main field, they will fallback to using the default index.js, (see specification here). For all the other packages, this is fine because the file is indeed stored at ./index.js, however for p-queue, the file is stored in ./dist/index.js. Not sure why webpack (and other bundlers) are ignoring the exports directive though. Could be a bug or ambiguity in the specifications. Maybe the projects using p-queue needs to have "type": "module" set?

kolyasya commented 10 months ago

import PQueue from 'p-queue/dist'; worked for me in Meteor app.

This should be documented somehow 🤔

joao-furtado-SADA commented 8 months ago

After wasting hours of my life looking for a solution to this, the only thing that comes to my mind is:

Why the hell JS/TS cannot simply WORK?

I love TS, but it's impressive how you just waste a ton of time chasing around zero-value env-related issues because someone decided that ESM was a good idea.

Sorry for the rant

Back to work

lightrow commented 4 months ago

import PQueue from 'p-queue/dist' no longer works when moduleResolution is NOT set to "Node" (Node16) with react native 0.74

Ok it works, you just need to redeclare the types

// esm.d.ts

declare module 'p-queue/dist' {
    export * from 'p-queue';
    export { default } from 'p-queue';
}

declare module 'p-memoize/dist' {
    export * from 'p-memoize';
    export { default } from 'p-memoize';
}