50

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"
      }
Kaustubh Khare
  • 3,280
  • 2
  • 32
  • 48

8 Answers8

144

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.

ihor marusyk
  • 1,960
  • 1
  • 12
  • 12
  • 8
    This answer solved the same issue after Angular update. Nice! – blackhard Jan 22 '21 at 16:49
  • 2
    This should be the right answer. Works for me. – Jeonsoft FaceBundy Jan 23 '21 at 05:40
  • @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. – Tanzeel Jun 07 '21 at 18:07
  • This solution fixed the error "Unknown version 95 of android" when build, after update from ng 13.1.1 to 13.2.5 – Sergio Rinaudo Mar 05 '22 at 16:10
  • 1
    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 ``` – ciantrius Mar 21 '22 at 09:22
  • 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! – Tobias Sporer Jul 07 '22 at 10:16
  • Worked for me when I got 'BrowserslistError: Unknown version 101 of android'. – propatience Aug 03 '22 at 11:37
  • 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. – Henrik Bøgelund Lavstsen Nov 24 '22 at 04:41
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

user1543276
  • 436
  • 5
  • 11
  • 1
    Tried. But same issue. – Kaustubh Khare Sep 30 '19 at 14:20
  • 2
    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. – user1543276 Oct 02 '19 at 14:27
  • Tried this one as well. But same issue. – Kaustubh Khare Oct 04 '19 at 09:14
  • @KaustubhKhare, I'm facing the exact issues. How did you solve this error. Please help. I'm stuck since last 4 days. – Tanzeel Jun 07 '21 at 18:27
  • @Tanzeel 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`. – Kaustubh Khare Jun 08 '21 at 04:25
  • This worked for me too after upgrading Angular, but since I'm using yarn, I had to delete `yarn.lock`. Thanks! – adam0101 Sep 18 '22 at 20:00
3

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.

Badawi
  • 51
  • 5
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.

Ruthi
  • 312
  • 1
  • 4
  • 12
  • @kaustubh-khare Are you change your package.json file with versions that I mentioned above? which version of angular and angular-cli you use? – Ruthi Nov 01 '19 at 08:38
  • Yes, I already tried this as well. If you check all answers and comments, then you will find your solution was already mentioned. – Kaustubh Khare Nov 01 '19 at 16:00
1

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

iwhp
  • 843
  • 6
  • 16
  • after updating all npm packages, try running --- npm install --- again, maybe it helps to brings some ^-version-packages up-to-date. – iwhp Sep 30 '19 at 18:17
1

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

Dharman
  • 30,962
  • 25
  • 85
  • 135
Yuchu Lei
  • 11
  • 2
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

ktsangop
  • 1,013
  • 2
  • 16
  • 29
-6

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...

  • This worked. Can I pass `ignoreUnknownVersions : true` from somewhere ? – Kaustubh Khare Oct 04 '19 at 09:15
  • 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? – Michael Kargl Feb 20 '20 at 10:48
  • 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. :-( – Tanzeel Jun 07 '21 at 18:24