'Error with angular & angular/cli versions

I have this error on angular docker project:

industrialareas_angular_ctnr | This version of CLI is only compatible with Angular versions ^13.0.0-next || >=13.0.0 <14.0.0,
industrialareas_angular_ctnr | but Angular version 12.2.16 was found instead.

My Dockerfile-angular file is:

FROM node:14
WORKDIR /usr/src/app
RUN npm uninstall -g @angular/cli
RUN npm uninstall @angular/cli
RUN npm i @angular/[email protected]
RUN npm cache clean --force
COPY ./project/package*.json .
RUN npm install
RUN npm link @angular/cli
COPY ./project .
EXPOSE 4200
CMD npm start

My docker-compose.yml file is:

version: '3.7'
services:
  angular:
    container_name: industrialareas_angular_ctnr
    build:
      context: .
      dockerfile: Dockerfile-angular
    restart: unless-stopped
    volumes:
      - ./project/src:/usr/src/app/src
    ports:
      - 4200:4200

And the package.json file is:

...
"dependencies": {
  ...
  "@angular/core": "~12.2.0",
  ...
},
"devDependencies": {
  ...
  "@angular/cli": "~12.2.8",
  ...

I have checked compatibility versions on this link

Anybody could help me please ? Thanks in advance.



Solution 1:[1]

The problem was that node brings the latest predefined version of angular cli, specifically @angular/[email protected] and the docker command took that by default.

Replace this line on Dockerfile:

RUN npm link @angular/cli

to this:

RUN npm link @angular/[email protected]

and all works ok !

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alberto Sanmartin Martinez