update-db icon indicating copy to clipboard operation
update-db copied to clipboard

browserslist package not detected with yarn

Open BoGnY opened this issue 10 months ago • 4 comments

I've tried to run yarn dlx update-browserslist-db@latest but I get the following error:

➤ YN0000: · Yarn 4.5.3
➤ YN0000: ┌ Resolution step
➤ YN0085: │ + update-browserslist-db@npm:1.1.1, escalade@npm:3.2.0, picocolors@npm:1.1.1
➤ YN0000: └ Completed in 0s 258ms
➤ YN0000: ┌ Post-resolution validation
➤ YN0002: │ root-workspace-0b6124@workspace:. doesn't provide browserslist (pa02ec), requested by update-browserslist-db.
➤ YN0086: │ Some peer dependencies are incorrectly met by your project; run yarn explain peer-requirements <hash> for details, where <hash> is the six-letter p-prefixed code.
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0013: │ 3 packages were added to the project (+ 37.6 KiB).
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed
➤ YN0000: · Done with warnings in 0s 311ms

Latest version:     1.0.30001690
Updating caniuse-lite version
$ yarn up -R caniuse-lite
caniuse-lite has been successfully updated

Error: update-browserslist-db tried to access browserslist (a peer dependency) but it isn't provided by your application; this makes the require call ambiguous and unsound.

Required package: browserslist
Required by: update-browserslist-db@virtual:dc3fc578bfa5e06182a4d2be39ede0bc5b74940b1ffe0d70c26892ab140a4699787750fba175dc306292e80b4aa2c8c5f68c2a821e69b2c37e360c0dff36ff66#npm:1.1.1 (via C:\Users\Luca\AppData\Local\Temp\xfs-ddf9ab0a\dlx-21912\.yarn\__virtual__\update-browserslist-db-virtual-06cd985fe4\0\cache\update-browserslist-db-npm-1.1.1-16e34017b1-536a2979ad.zip\node_modules\update-browserslist-db\)
Ancestor breaking the chain: root-workspace-0b6124@workspace:.


Require stack:
- C:\Users\Luca\AppData\Local\Temp\xfs-ddf9ab0a\dlx-21912\.yarn\__virtual__\update-browserslist-db-virtual-06cd985fe4\0\cache\update-browserslist-db-npm-1.1.1-16e34017b1-536a2979ad.zip\node_modules\update-browserslist-db\index.js 
- C:\Users\Luca\AppData\Local\Temp\xfs-ddf9ab0a\dlx-21912\.yarn\__virtual__\update-browserslist-db-virtual-06cd985fe4\0\cache\update-browserslist-db-npm-1.1.1-16e34017b1-536a2979ad.zip\node_modules\update-browserslist-db\cli.js   
    at require$$0.Module._resolveFilename (C:\Users\Luca\AppData\Local\Temp\xfs-ddf9ab0a\dlx-21912\.pnp.cjs:5676:13)
    at Module._load (node:internal/modules/cjs/loader:984:27)
    at require$$0.Module._load (C:\Users\Luca\AppData\Local\Temp\xfs-ddf9ab0a\dlx-21912\.pnp.cjs:5567:31)
    at Module.require (node:internal/modules/cjs/loader:1231:19)
    at require (node:internal/modules/helpers:179:18)
    at getBrowsers (C:\Users\Luca\AppData\Local\Temp\xfs-ddf9ab0a\dlx-21912\.yarn\__virtual__\update-browserslist-db-virtual-06cd985fe4\0\cache\update-browserslist-db-npm-1.1.1-16e34017b1-536a2979ad.zip\node_modules\update-browserslist-db\index.js:90:22)
    at updateDB (C:\Users\Luca\AppData\Local\Temp\xfs-ddf9ab0a\dlx-21912\.yarn\__virtual__\update-browserslist-db-virtual-06cd985fe4\0\cache\update-browserslist-db-npm-1.1.1-16e34017b1-536a2979ad.zip\node_modules\update-browserslist-db\index.js:287:15)
    at Object.<anonymous> (C:\Users\Luca\AppData\Local\Temp\xfs-ddf9ab0a\dlx-21912\.yarn\__virtual__\update-browserslist-db-virtual-06cd985fe4\0\cache\update-browserslist-db-npm-1.1.1-16e34017b1-536a2979ad.zip\node_modules\update-browserslist-db\cli.js:34:5)
    at Module._compile (node:internal/modules/cjs/loader:1369:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)

Problem with browser list retrieval.
Target browser changes won’t be shown.

I've tried to add browserslist to package.json (previously not included but only required by autoprefixer) but nothing changes

BoGnY avatar Jan 07 '25 15:01 BoGnY

Seems like you also have monorepo.

Sorry, this issue is related to a complex environment reproduction.

You need to debug it on your machine and find a fix.

ai avatar Jan 07 '25 18:01 ai

No it's not a monorepo.

I can reproduce with this package.json:

{
    "name": "test",
    "packageManager": "[email protected]",
    "devDependencies": {
        "autoprefixer": "^10.4.2",
        "browserslist": "^4.24.3",
        "postcss": "^8.4.14"
    }
}

EDIT: Just tried with an empty dockerized env with only node 20, corepack enabled and yarn 4.6.0 installed, to see if is my env or not, but I've got the same problem.

docker run -it --entrypoint bash node:20

and inside shell:

cd /home/node
corepack enable
yarn init
yarn add autoprefixer browserslist -D
yarn dlx update-browserslist-db@latest

BoGnY avatar Jan 08 '25 08:01 BoGnY

Yes, seems like we have a problem with new Yarn.

But don’t worry. It is not a big error. It is an error in a system which shows browser diff before/after update. You can use tool without this diff.

I made this message less aggressive https://github.com/browserslist/update-db/commit/80603227f599ebbd186001fd3fa577125ded46ee

If somebody will know a way to fix it properly for Yarn, please send PR.

ai avatar Jan 08 '25 11:01 ai

The problem is at L90 of index.js, caused by require('browserslist')..

yarn dlx commands are executed on a virtual root workspace which miss the browserslist package and cannot be accessed to add manually the missing package.. maybe including a workspace section on package.json could be fix it, IDK I'm a backend dev so I know very low frontend languages..

For now I have found a workaround using the command yarn dlx -p browserslist -p update-browserslist-db update-browserslist-db which install the specified packages (inside virtual root workspace) before executing the script.

BoGnY avatar Jan 09 '25 18:01 BoGnY