browserslist / update-db

CLI tool to update caniuse-lite to refresh target browsers from Browserslist config
https://browsersl.ist/
MIT License
286 stars 57 forks source link

Since v1.0.14 → Error: Cannot find module 'browserslist' #36

Closed davidesigner closed 2 months ago

davidesigner commented 2 months ago

Hi there,

Since the new release (1.0.14), my team and myself have this error when we run npx update-browserslist-db@latest.

Latest version:     1.0.30001615
Installed version:  1.0.30001615
caniuse-lite is up to date
caniuse-lite has been successfully updated

Error: Cannot find module 'browserslist'
Require stack:
- /Users/xxxx/.npm/_npx/2662cbd72e57abb6/node_modules/update-browserslist-db/index.js
- /Users/xxxx/.npm/_npx/2662cbd72e57abb6/node_modules/update-browserslist-db/cli.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1143:15)
    at Module._load (node:internal/modules/cjs/loader:984:27)
    at Module.require (node:internal/modules/cjs/loader:1231:19)
    at require (node:internal/modules/helpers:179:18)
    at getBrowsers (/Users/xxxx/.npm/_npx/2662cbd72e57abb6/node_modules/update-browserslist-db/index.js:78:22)
    at updateDB (/Users/xxxx/.npm/_npx/2662cbd72e57abb6/node_modules/update-browserslist-db/index.js:273:15)
    at Object.<anonymous> (/Users/xxxx/.npm/_npx/2662cbd72e57abb6/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)
    at Module.load (node:internal/modules/cjs/loader:1206:32)

Problem with browser list retrieval.
Target browser changes won’t be shown.
ai commented 2 months ago
  1. What package manager do you use?
  2. Do you have Browserslists in your lock file?
  3. Do you use monorepo?
davidesigner commented 2 months ago

I use npm and I don't have browserlist in my lock file because it was not required by the previous version.

Yes we have a monorepo that contains multiple js projects (yarn & npm).

ai commented 2 months ago

Why do you need caniuse-lite if you don’t have Browserslist?

ai commented 2 months ago

Very strange, we call browserslist in try-catch and ready for error from require().

What is Node.js version?

davidesigner commented 2 months ago

Sorry I have browserlist in my package-lock.json because it's a dependency of autoprefixer.

The package is installed in my node_modules:

Screenshot 2024-05-02 at 16 42 28

Node: v20.12.0

ai commented 2 months ago

Seems like update-browserslist-db doesn’t see browserslist because it was run from temporary dir.

But I have no idea why this code is not working https://github.com/browserslist/update-db/blob/main/index.js#L274-L276

Do you have any way to reproduce the problem and debug it?

davidesigner commented 2 months ago

You can do that: npx create-remix@latest --template remix-run/indie-stack to install a new Remix project that have the problem:

Screenshot 2024-05-02 at 16 55 43

Then, just go to the project repository and run: npx update-browserslist-db@latest.

Environment:

ai commented 2 months ago

It was not an error (the exit code was 0), just a warning.

But I improve the text https://github.com/browserslist/update-db/commit/1f3ab06d79cfee9d8944a9379f1d15dad9a83a28