BrowserslistError: Unknown version 67 of android
Asked Answered
Z

8

53

I have created one angular library using angular 8 and CLI 8. I am trying to build the library, but I am getting the error.

ng build <lib-name>

I have gone through some questions posted related to this error, most of them say remove node_modules and reinstall them. I tried this solution but still, I am getting the following error.

[Browserslist] Could not parse package.json. Ignoring it.

ERROR: Unknown version 67 of android
Unknown version 67 of android
BrowserslistError: Unknown version 67 of android
        at Function.select (C:\Users\kaukhare\github\ngx-group-by-alphabates\node_modules\ng-packagr\node_modules\autoprefixer\node_modules\browserslist\index.js:924:17)
        at C:\Users\kaukhare\github\ngx-group-by-alphabates\node_modules\ng-packagr\node_modules\autoprefixer\node_modules\browserslist\index.js:252:33
        at Array.reduce (<anonymous>)
        at resolve (C:\Users\kaukhare\github\ngx-group-by-alphabates\node_modules\ng-packagr\node_modules\autoprefixer\node_modules\browserslist\index.js:234:18)
        at browserslist (C:\Users\kaukhare\github\ngx-group-by-alphabates\node_modules\ng-packagr\node_modules\autoprefixer\node_modules\browserslist\index.js:353:16)
        at Browsers.parse (C:\Users\kaukhare\github\ngx-group-by-alphabates\node_modules\ng-packagr\node_modules\autoprefixer\lib\browsers.js:66:12)
        at new Browsers (C:\Users\kaukhare\github\ngx-group-by-alphabates\node_modules\ng-packagr\node_modules\autoprefixer\lib\browsers.js:48:26)
        at loadPrefixes (C:\Users\kaukhare\github\ngx-group-by-alphabates\node_modules\ng-packagr\node_modules\autoprefixer\lib\autoprefixer.js:101:20)
        at plugin (C:\Users\kaukhare\github\ngx-group-by-alphabates\node_modules\ng-packagr\node_modules\autoprefixer\lib\autoprefixer.js:112:20)
        at LazyResult.run (C:\Users\kaukhare\github\ngx-group-by-alphabates\node_modules\postcss\lib\lazy-result.js:295:14)
        at LazyResult.sync (C:\Users\kaukhare\github\ngx-group-by-alphabates\node_modules\postcss\lib\lazy-result.js:281:26)
        at LazyResult.warnings (C:\Users\kaukhare\github\ngx-group-by-alphabates\node_modules\postcss\lib\lazy-result.js:85:17)
        at StylesheetProcessor.process (C:\Users\kaukhare\github\ngx-group-by-alphabates\node_modules\ng-packagr\lib\ng-v5\entry-point\resources\stylesheet-processor.js:47:16)
        at Object.readResource (C:\Users\kaukhare\github\ngx-group-by-alphabates\node_modules\ng-packagr\lib\ts\cache-compiler-host.js:73:57)
        at TsCompilerAotCompilerTypeCheckHostAdapter.loadResource (C:\Users\kaukhare\github\ngx-group-by-alphabates\node_modules\@angular\compiler-cli\src\transformers\compiler_host.js:495:37)
        at Object.get (C:\Users\kaukhare\github\ngx-group-by-alphabates\node_modules\@angular\compiler\bundles\compiler.umd.js:26490:94)

What can be the issue? Is this error is due to autoprefixer? What should I do to solve this issue?

package-lock.json

"ng-packagr": {
      "version": "5.5.1",
      "resolved": "https://registry.npmjs.org/ng-packagr/-/ng-packagr-5.5.1.tgz",
      "integrity": "sha512-GT6QK5WAirQwALdeJPiXdgRd5PzRqcknb/C/G+cCDEbUFri4oGVmns2Nl4I0FGg/cRn6nXTxRiUunOSqZ3Lehw==",
      "dev": true,
      "requires": {
        "ajv": "^6.10.2",
        "autoprefixer": "^9.6.0",
        "browserslist": "^4.0.0"
},
    "autoprefixer": {
      "version": "9.5.1",
      "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-9.5.1.tgz",
      "integrity": "sha512-KJSzkStUl3wP0D5sdMlP82Q52JLy5+atf2MHAre48+ckWkXgixmfHyWmA77wFDy6jTHU6mIgXv6hAQ2mf1PjJQ==",
      "dev": true,
      "requires": {
        "browserslist": "^4.5.4",
        "caniuse-lite": "^1.0.30000957",
        "normalize-range": "^0.1.2",
        "num2fraction": "^1.2.2",
        "postcss": "^7.0.14",
        "postcss-value-parser": "^3.3.1"
      }
Zedoary answered 29/9, 2019 at 13:10 Comment(0)
S
151

The thing that solved it for me was running

npx browserslist --update-db

in project root. This made changes to package-lock.json updating versions of caniuse-lite.

To give some context, I landed on this question because I was getting this error:

Compiling TypeScript sources through ngc
ERROR: Unknown version 80 of android
An unhandled exception occurred: Unknown version 80 of android

after I upgraded angular from 9.x.x to 10.x.x. I was getting this error both on my dev machine and in CI, so removing node_modules and package-lock.json was not really an option.

Sporangium answered 18/1, 2021 at 22:47 Comment(9)
This answer solved the same issue after Angular update. Nice!Parkinson
This should be the right answer. Works for me.Coonskin
@ihor, I'm facing the exact issue with my library also. But this solution is not working. I'm still getting the same version 67 android error. Please help.Rayner
This solution fixed the error "Unknown version 95 of android" when build, after update from ng 13.1.1 to 13.2.5Anatola
This also fixed my issue in an upgrade to Angular 13, thank you. I also encountered an error running ``` npx browserslist ``` as I use a shrinkwrap rather than package lock. If anyone else gets this error try running ``` npx browserslist@latest --update-db ```Trilinear
Thank you very much for that answer, it helped me to solve the problem with "Unkown version xx of android" when upgrading to Angular 14. But I also had to delete the node_modules folder!Linsk
Worked for me when I got 'BrowserslistError: Unknown version 101 of android'.Grieco
had to downgrade a node version since build server did not like package-lock v2, and after i got this issue with a different version. but fixed it.Landrum
This fixed my issue going from Angular 14 to 15Olodort
K
12

I'm seeing this too... like you, deleting node_modules and re-running npm install did not work.

What did work, however, was deleting node_modules AND deleting package-lock.json, and then running npm i.

Try that...

Andrew

Kakaaba answered 29/9, 2019 at 22:16 Comment(6)
Tried. But same issue.Zedoary
I also had to make sure I had the latest @angular-devkit... "@angular-devkit/build-angular": "^0.801.3", "@angular-devkit/build-ng-packagr": "^0.801.3", .. in my package.json. Once I fixed that, wiped node_modules, it worked.Kakaaba
Tried this one as well. But same issue.Zedoary
@KaustubhKhare, I'm facing the exact issues. How did you solve this error. Please help. I'm stuck since last 4 days.Rayner
@Rayner Accepted answer is the one. Are you facing an issue with the local machine after doing changes? Have you tried removing node_modules after updating browserslist.Zedoary
This worked for me too after upgrading Angular, but since I'm using yarn, I had to delete yarn.lock. Thanks!Delrio
T
4

This might be too late, but I'm gonna post how I solved the issue, because I ran into it very recently (late Feb. 2022), and I followed a different approach that resulted in minimal changes to my project.
I had a similar issue with a project downloaded from StackBlitz, but in my case the unknown version of android was 97 instead of 67 or 80.
The browserslist database was up to date, deleting the node_modules directory and running npm install did not change anything (checked by using a comparison tool), updating the project's dependencies caused even more trouble, and so did deleting package-lock.json.

What worked in my case was specifying 98 as the target version of android (instead of 97) in .browserslistrc in the project's root directory (I actually had to create that file, as it didn't exist).

This is how I found out that version 98 works:
I first temporarily edited the code where the exception occurred (in node_modules\browserslist\index.js). Right before the line that throws the exception, I inserted this statement:

if (name === 'android') {
  return arguments.callee(context, name, (version - 1).toString())
}

to find the largest number less than 97 that is accepted. Then I ran npx browserslist and found that version to be 4.
Dissatisfied, I tried larger version numbers by replacing the above snippet with this one:

if (name === 'android' && Number(version) < 200) {
  return arguments.callee(context, name, (Number(version) + 1).toString())
}

and fortunately, 98 worked (verified by running npx browserslist again).
So I undid my changes to the code, grabbed that output from npx browserslist, and saved it in .browserslistrc (I also had to exclude safari due to another bug).
The ng build command then proceeded successfully.

Taster answered 2/3, 2022 at 10:13 Comment(0)
L
2

Try this:

1.Deleting the entire node_modules directory.

2.Deleting package-lock.json from the root directory.

3.Making sure the latest @angular-devkit projects were referenced in package.json:

"@angular-devkit/build-angular": "^0.801.3", "@angular-devkit/build-ng-packagr": "^0.801.3".

4.Close and reopen cmd window.

Running npm install.

Lacerta answered 31/10, 2019 at 12:1 Comment(2)
@kaustubh-khare Are you change your package.json file with versions that I mentioned above? which version of angular and angular-cli you use?Lacerta
Yes, I already tried this as well. If you check all answers and comments, then you will find your solution was already mentioned.Zedoary
I
2

Can be caused by outdated babel. Try update babel using npx babel-upgrade --write and then npx browserslist@latest --update-db.

Inbred answered 7/5, 2021 at 1:32 Comment(0)
O
1

I updated all the npm packages and the error went away.

Obola answered 30/9, 2019 at 8:34 Comment(1)
after updating all npm packages, try running --- npm install --- again, maybe it helps to brings some ^-version-packages up-to-date.Obola
S
0

TL;DR; Your .browserslistrc entries might be invalid, or suddenly not understood by some of your packages. Try to remove/replace them.

I encountered this after installing @angular-architects/module-federation on an Angular project. My existing .browserslistrc was:

> 0.5%
last 2 versions
Firefox ESR
not dead
not IE 9-11 # For IE 9-11 support, remove 'not'.

Somehow after the above package got installed, the following error showed up : BrowserslistError: Unknown version 103 of android

Just commented out my .browserslistrc entries, and got rid of this. No idea why a package installation would cause this

Stealing answered 8/9, 2022 at 12:56 Comment(0)
P
-7

Try to modify \node_modules\ng-packagr\node_modules\autoprefixer\node_modules\browserslist\index.js at row 924 as follow:

if (alias) {
      version = alias
    } else if (context.ignoreUnknownVersions) {
      return []
    } else {
      throw new BrowserslistError(
        'Unknown version ' + version + ' of ' + name)
    }

in

if (alias) {
      version = alias
    } else if (context.ignoreUnknownVersions) {
      return []
    } else {
      return []
    }

I hope help you... this is dirty solution...

Psalmbook answered 1/10, 2019 at 19:55 Comment(3)
This worked. Can I pass ignoreUnknownVersions : true from somewhere ?Zedoary
Could you please add a little bit more context and explanation as to what the solution actually does and why this would be a valid solution?Nijinsky
This worked. But -4 downvotes is a big-red flag. This is the only solution that is working for me but this is dirty. What to do. :-(Rayner

© 2022 - 2024 — McMap. All rights reserved.