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

`npx update-browserslist-db@latest` fails #16

Closed LeonMelis closed 1 year ago

LeonMelis commented 1 year ago

I'm trying to update browserlist, but the update script fails.

I tried both npx update-browserslist-db@latest and npx browserslist@latest --update-db, they both throw the same error:

npx update-browserslist-db@latest
/home/user/.npm/_npx/2662cbd72e57abb6/node_modules/update-browserslist-db/cli.js:39
      throw e
      ^

SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at getLatestInfo (/home/user/.npm/_npx/2662cbd72e57abb6/node_modules/update-browserslist-db/index.js:76:15)
    at updateDB (/home/user/.npm/_npx/2662cbd72e57abb6/node_modules/update-browserslist-db/index.js:264:16)
    at Object.<anonymous> (/home/user/.npm/_npx/2662cbd72e57abb6/node_modules/update-browserslist-db/cli.js:34:5)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:22:47
npx browserslist@latest --update-db
undefined:1

SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at getLatestInfo (/home/user/.npm/_npx/072487b38308305a/node_modules/update-browserslist-db/index.js:76:15)
    at updateDB (/home/user/.npm/_npx/072487b38308305a/node_modules/update-browserslist-db/index.js:264:16)
    at Object.<anonymous> (/home/user/.npm/_npx/072487b38308305a/node_modules/browserslist/cli.js:42:3)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:22:47

I tried removing the cache file at /home/user/.npm but to no avail. Am using node v16.18.1, npm 9.6.1 and yarn 1.22.19.

I suspect a corrupt cache file somewhere, is there anything else I could purge?

ai commented 1 year ago

Can you debug the code to find why package manager started to output incorrect JSON?

LeonMelis commented 1 year ago

Well, this is very awkward, I ran npx update-browserslist-db@latest with a debugger attached using IntelliJ... and it installed flawlessly... I guess that makes this a Heisenbug then?

However, when observing met yarn.lock file, it appeared that npx update-browserslist-db@latest had downgraded hundreds of babel related packages (from 7.19.x to 7.16.x), and rewritten a lot of packages with npm repositories instead of yarn... 🤔 I guess that is just the current JS dependency mess we'll have to live with, but it might be that there is some incompatibility with later Babel versions?

ai commented 1 year ago

I recommend just moving to pnpm, the only good package manager.

LeonMelis commented 1 year ago

2021: Just use npm! It's so much better! 2022: Just use yarn! It's so much better! 2023: Just use pnpm! It's so much better!

Sorry for the rant, but the JS ecosystem has become a terrible mess, I'm just tired of it.

For anyone else running into this problem, you can add the following to the scripts section of your package.json

"script": {
 ...
 "npx": "npx"
}

Then run ~npm~ ~yarn~, sorry, I mean pnpm npx update-browserslist-db@latest and it should work, if you are lucky.

I'll close this ticket, I don't think there is anything else we can do here.

nickiaconis commented 11 months ago

Just an fyi that pnpm dlx is pnpm's equivalent of npx in transient download mode. Defining the "npx" script—or calling npx at all, for that matter—shouldn't be necessary when using pnpm.

lionel-bijaoui commented 8 months ago

It's happening to me with npm (v10.2.0 and v10.2.1) and bun (v1.0.6) on Ubuntu 22.04.3. Can you please reopen this issue ?

ai commented 8 months ago

@lionel-bijaoui with Bun it is a different issue. We already have it.

Somebody need to send PR with Bun support.

lionel-bijaoui commented 8 months ago

The error message is the same across npm and bun. I hope these details can help

With NPM

npx update-browserslist-db@latest
<censored>/node_modules/update-browserslist-db/cli.js:39
      throw e
      ^

SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at getLatestInfo (<censored>/.npm/_npx/2662cbd72e57abb6/node_modules/update-browserslist-db/index.js:73:15)
    at updateDB (<censored>.npm/_npx/2662cbd72e57abb6/node_modules/update-browserslist-db/index.js:272:16)
    at Object.<anonymous> (<censored>/.npm/_npx/2662cbd72e57abb6/node_modules/update-browserslist-db/cli.js:34:5)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:86:12)
    at node:internal/main/run_main_module:23:47

Node.js v18.18.0

With Bun

bunx update-browserslist-db@latest
/tmp/update-browserslist-db@latest--bunx/node_modules/update-browserslist-db/cli.js:39
      throw e
      ^

SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at getLatestInfo (/tmp/update-browserslist-db@latest--bunx/node_modules/update-browserslist-db/index.js:73:15)
    at updateDB (/tmp/update-browserslist-db@latest--bunx/node_modules/update-browserslist-db/index.js:272:16)
    at Object.<anonymous> (/tmp/update-browserslist-db@latest--bunx/node_modules/update-browserslist-db/cli.js:34:5)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:86:12)
    at node:internal/main/run_main_module:23:47

Node.js v18.18.0

Is there a way to do the update manually ? What are the steps ? I only need to update caniuse-lite to it's latest version ? Thank you for your help !

ai commented 8 months ago

The error message is equal but the reason is different.

I am not Bun user, you need to find out yourself and then help other sending PR.

Remember, open source is not a free support but rather collective way to help each other where everyone is contributing something.

lionel-bijaoui commented 8 months ago

I'm sorry for the confusion about bun. I also and more importantly have the same error with NPM.

I have updated to node 20 and the error disappeared.

Have a great day !

stijns96 commented 4 months ago

Well... this was doing the trick for me... I don't have caniuse-lite installed, but simply running npm update browserslist did it for me.