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

TypeError: Cannot read properties of undefined (reading 'replace') #11

Closed captbaritone closed 1 year ago

captbaritone commented 1 year ago

When I build my app I get prompted (several times) to run npx browserslist@latest --update-db. However, when I do I get an error TypeError: Cannot read properties of undefined (reading 'replace')

Steps to reproduce

git clone git@github.com:captbaritone/webamp.git
cd webamp
yarn
npx browserslist@latest --update-db

Actual outcome

╭─[00:00]: captbaritone at moffo in ~/tmp/webamp on branch*
╰─➤ npx browserslist@latest --update-db
Browserslist: caniuse-lite is outdated. Please run:
  npx browserslist@latest --update-db
  Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating
Latest version:     1.0.30001412
/Users/captbaritone/tmp/webamp/node_modules/@babel/core/node_modules/browserslist/update-db.js:155
          ? lines[3].replace(
                     ^

TypeError: Cannot read properties of undefined (reading 'replace')
    at /Users/captbaritone/tmp/webamp/node_modules/@babel/core/node_modules/browserslist/update-db.js:155:22
    at Array.forEach (<anonymous>)
    at updateYarnLockfile (/Users/captbaritone/tmp/webamp/node_modules/@babel/core/node_modules/browserslist/update-db.js:141:10)
    at updateLockfile (/Users/captbaritone/tmp/webamp/node_modules/@babel/core/node_modules/browserslist/update-db.js:226:12)
    at updatePackageManually (/Users/captbaritone/tmp/webamp/node_modules/@babel/core/node_modules/browserslist/update-db.js:232:22)
    at updateDB (/Users/captbaritone/tmp/webamp/node_modules/@babel/core/node_modules/browserslist/update-db.js:327:5)
    at Object.<anonymous> (/Users/captbaritone/tmp/webamp/node_modules/@babel/core/node_modules/browserslist/cli.js:42:3)
    at Module._compile (node:internal/modules/cjs/loader:1120:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1174:10)
    at Module.load (node:internal/modules/cjs/loader:998:32)

Node.js v18.7.0

Versions

╭─[00:00]: captbaritone at moffo in ~/tmp/webamp on branch*
╰─➤ node --version
v18.7.0
╭─[00:00]: captbaritone at moffo in ~/tmp/webamp on branch*
╰─➤ yarn --version
1.22.10
╭─[00:00]: captbaritone at moffo in ~/tmp/webamp on branch*
╰─➤ npm --version
8.15.0
╭─[00:00]: captbaritone at moffo in ~/tmp/webamp on branch*
╰─➤ npx --version
8.15.0

Observation

I was prompted to report this issue here via this tweet but in filing this issue I realized that the command I was prompted to run npx browserslist@latest --update-db is different than the on in this repository's readme, which is: npx update-browserslist-db@latest.

If I run npx update-browserslist-db@latest I get a better outcome (full output of that can be found in this gist)

ai commented 1 year ago

Seems like it is npm cache issue.

For some reason, it used old Browserslist. Sorry, I have no idea how to fix it. Let’s just use npx update-browserslist-db@latest instead since it works.

I also recommend update browserslist in the project.

captbaritone commented 1 year ago

@ai I'm confused as to how it could be an npm cache issue if it repros on a fresh clone.

Is the core issue that the update message that I'm getting from my build tool is now out of date?

ai commented 1 year ago

There is no anymore update-db.js script in browserslist npm package https://github.com/browserslist/browserslist

TypeError: Cannot read properties of undefined (reading 'replace')
    at /Users/captbaritone/tmp/webamp/node_modules/@babel/core/node_modules/browserslist/update-db.js:155:22

Also, note that npm took browserslist from @babel/core and didn’t install fresh version to local npm cache.

captbaritone commented 1 year ago

I see, so npx seems to be ignoring the @latest version, specifier, and is instead using an outdated version that it found locally.

Should I be reporting this as a bug to npm/npx then?

ai commented 1 year ago

If you are using the latest version, yes, we can try (I am not sure that we will be lucky with any solution soon)