Nyalab / caniuse-api

request the caniuse data to check browsers compatibilities
MIT License
356 stars 27 forks source link

`caniuse.isSupported('transform-box', 'ie 10') ` an error occurred #52

Open mantou132 opened 7 years ago

mantou132 commented 7 years ago

TypeError: Cannot read property 'stats' of undefined at /home/upyun/impress-website/node_modules/caniuse-api/dist/index.js:78:16

MoOx commented 7 years ago

Looks like a bug that could be prevented... Maybe some data source have a different format that what we expect. Mind taking a look for a PR @mantou132 ?

MoOx commented 7 years ago

@Nyalab it seems here https://github.com/Nyalab/caniuse-api/blob/ca59a968f4f96963c8a60cfd188f0d885b8320fa/src/index.js#L52 data are not verified (and can be undefined). This tests approve this https://github.com/Nyalab/caniuse-api/blob/ca59a968f4f96963c8a60cfd188f0d885b8320fa/test/index.js#L60

But caniuse.isSupported('transform-box', 'ie 10') does not looks like a silly thing. Thoughts?

axe312ger commented 7 years ago

I ran into the same issue with another feature: css-rrggbbaa

Would be awesome if we could just display a warning when stats are not present, since simply the caniuse-db is to old in my dependency chain.

The source of the issue I guess is that postcss-cssnext has a pretty "old" autoprefixer version. --> https://github.com/MoOx/postcss-cssnext/blob/master/package.json#L24

axe312ger commented 7 years ago

I am pretty sure this related to

Edit: Updating autoprefixer in a fork of postcss-cssnext also fixed the issie for me. Also making https://github.com/Nyalab/caniuse-api/blob/ca59a968f4f96963c8a60cfd188f0d885b8320fa/src/index.js#L52 throw a warning when the feature is missing the stats

MoOx commented 7 years ago

Sorry but ^6.* will get you latest version of autoprefixer. Uninstalling cssnext and reinstalling it will not make this bug a thing.

axe312ger commented 7 years ago

Whoot yeah, you are totally right.

I deleted node_modules multiple times, but that didn't help. My issue was, that I was using yarn to lock down my dependencies. Thats what caused the old caniuse-db to be present on my system.

Might be worth a info in the readme, that postcss-cssnext relies on caniuse-db/data.json and with locked dependencies with shrinkwrap/yarn you may get errors since your database is out of date.

I still think showing a warning instead of provoking an error would be the better behaviour for caniuse-api. Locked down dependencies are not that super special and I will not be the last person running into this.