29

I created a new angular app with the angular CLI 13.0.4. It created an angular app version ~13.0.0. When I use the command ng build, I get the following error:

./node_modules/css-loader/dist/runtime/api.js - Error: Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):
Transform failed with 1 error:
error: Invalid version: "15.2-15.3"

./node_modules/css-loader/dist/runtime/noSourceMaps.js - Error: Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):
Transform failed with 1 error:
error: Invalid version: "15.2-15.3"

These are the different version that I use:

enter image description here

What should I do to fix this error?

------ UPDATE 3/2/2022 ------

Contents of the browserlist file:

# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
# For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries

# For the full list of supported browsers by the Angular framework, please see:
# https://angular.io/guide/browser-support

# You can see what browsers were selected by your queries by running:
#   npx browserslist

last 1 Chrome version
last 1 Firefox version
last 2 Edge major versions
last 2 Safari major versions
last 2 iOS major versions
Firefox ESR
wonderful world
  • 10,969
  • 20
  • 97
  • 194

10 Answers10

49

I commented out the line last 2 Safari major versions from the .browserslistrc file. The npm build is building the application successfully.

wonderful world
  • 10,969
  • 20
  • 97
  • 194
29

Try npm audit fix or npm audit fix --force since "error: Invalid version: "15.2-15.3"" this error is due to an invalid version installed, therefore as this was introduced in npm@6 audit fixing will automatically resolve dependence issues.

Jasper
  • 371
  • 3
  • 4
18

I had to run npm audit fix --force after updating .browserslistrc, and it worked for me.

How to find the angular Invalid version 15.2-15.3 error

H. Pauwelyn
  • 13,575
  • 26
  • 81
  • 144
7

Update this library to the latests major version and it should fix this issue

yarn add @angular-devkit/build-angular -D

if you are using angular 13 e.g. run this command

yarn add @angular-devkit/build-angular@13.3.7 -D

or the same using npm

npm i --save-dev @angular-devkit/build-angular@13.3.7
Freestyle09
  • 4,894
  • 8
  • 52
  • 83
5

The command "npm audit fix" works for me

YDY
  • 61
  • 4
3

enter image description here

I removed the last two Safari major versions from the .browserslistrc file after which the build is created successfully.

After removing the last two Safari major versions:

enter image description here

Ethan
  • 876
  • 8
  • 18
  • 34
3

You can simply add

not ios_saf 15.2-15.3
not safari 15.2-15.3

in your .browserslistrc file of your project

2

I got this problem after updating my browserslist, and npm update fixed it for me.

As explained here by an Angular collaborator:

This is just a bug in the parsing logic of Safari browser versions

eta32carinae
  • 473
  • 4
  • 12
1

If you want a solution without changing .browserslistrc file(npm audit fix didn't work for me as well), update angular compiler to version 13.2.5+ as per comment

"@angular-devkit/build-angular": "~13.2.5",
Lastsword
  • 71
  • 3
0

run npm audit fix --force. it will be worked for angular 13 version

Dushan
  • 1