vuejs-templates / webpack

A full-featured Webpack + vue-loader setup with hot reload, linting, testing & css extraction.
MIT License
9.7k stars 4.39k forks source link

Browserslist's 'major' version query not usable #1274

Open cngu opened 6 years ago

cngu commented 6 years ago

Environment

npm: 3.10.10 node: 6.11.4

Issue

Build fails when attempting to configure browserslist to use the last N major versions query.

Repro

1) In browserslist in package.json, change: "last 2 versions", to "last 2 major versions", 2) npm run build

Error

/Users/c/dev/new-template/node_modules/caniuse-api/node_modules/browserslist/index.js:37
    throw new BrowserslistError(name);
    ^
BrowserslistError: Unknown browser major
    at error (/Users/c/dev/new-template/node_modules/caniuse-api/node_modules/browserslist/index.js:37:11)
    at Function.browserslist.checkName (/Users/c/dev/new-template/node_modules/caniuse-api/node_modules/browserslist/index.js:320:18)
    at Function.select (/Users/c/dev/new-template/node_modules/caniuse-api/node_modules/browserslist/index.js:438:37)
    at /Users/c/dev/new-template/node_modules/caniuse-api/node_modules/browserslist/index.js:207:41
    at Array.forEach (native)
    at browserslist (/Users/c/dev/new-template/node_modules/caniuse-api/node_modules/browserslist/index.js:196:13)
    at cleanBrowsersList (/Users/c/dev/new-template/node_modules/caniuse-api/dist/utils.js:56:59)
    at setBrowserScope (/Users/c/dev/new-template/node_modules/caniuse-api/dist/index.js:29:43)
    at Object.<anonymous> (/Users/c/dev/new-template/node_modules/caniuse-api/dist/index.js:91:1)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
LinusBorg commented 6 years ago

I found this: https://github.com/angular/angular-cli/issues/9020#issuecomment-354374450

Which says that this option doesn'T work for autoprefixer <=7 - but we have 7.1 in our dependencies.

Can you check which version is installed in your /node_modules?

cngu commented 6 years ago

I'm using autoprefixer@7.2.5.

npm ls autoprefixer also shows that css-loader > cssnano is using an older version:

new-template@1.0.0 /Users/c/dev/new-template
├── autoprefixer@7.2.5 
└─┬ css-loader@0.28.9
  └─┬ cssnano@3.10.0
    └── autoprefixer@6.7.7   <--  old

But I'm not sure if that is the problem because the stacktrace suggests that caniuse-api is having issues, but it doesn't use autoprefixer and is using the latest version of browserslist.

LinusBorg commented 6 years ago

But I'm not sure if that is the problem

I would assume that's the issue indeed, if autoprefixer <7 doesn't support major.

https://github.com/ben-eb/cssnano/blob/v3.10.0/package.json#L26

cngu commented 6 years ago

I tested this out locally by adding an npm-shrinkwrap.json file to override css-loader > cssnano's version of autoprefixer to 7.2.5.

Unfortunately I'm still seeing the same caniuse-api stacktrace above.

Also note that major is the first and only query I tried and found it not to be working. There could potentially be other broken queries.

LinusBorg commented 6 years ago

Well, it must be something about either autoprefixer or cssnano. None of out code in the webpack config or anwhere else in this template uses the browserslist. And since npm run dev works (unless I misunderstood), we can assume that autoprefixer works and it must be cssnano (or one of its dependencies), which is the only one of the two running only during build.

cngu commented 6 years ago

Okay, we can try this again when the chain of dependencies have updated.

I believe this has to wait for... css-nano v4 - ben-eb/cssnano#365 (breaking changes) css-loader v1 - webpack-contrib/css-loader#654

...and then we can update when they're stable.

If there are no other tasks on your end, feel free to close this issue (or do whatever you usually do to track upstream issues). Thanks for the help!

LinusBorg commented 6 years ago

I'll leave this open to track it.