Angular 在 docker 中不起作用,因为它找不到模块 @angular-devkit/build-angular

Ven*_*kat 5 jasmine asp.net-mvc-4 protractor cucumberjs angular

我尝试忽略 node_modules 但仍然对我不起作用,即使在忽略 node_modules 之后我仍然面临同样的错误

yaml文件:

version: '3.5'

services:
    angular-docker:
        hostname: localhost
        container_name: angular-docker
        build: ./angular-doc
        volumes:
          - './angular-doc:/usr/src/app/'
        ports:
          - '4200:4200'
Run Code Online (Sandbox Code Playgroud)

泊坞窗文件:

FROM node:10.12.0

RUN mkdir usr/src/app

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install -g @angular/cli@latest

COPY . .

EXPOSE 4200

CMD ng serve --host 0.0.0.0
Run Code Online (Sandbox Code Playgroud)

mal*_*awi 1

您需要在 Angular 项目中安装@Angular-devkit/build-Angular包作为开发依赖项

npm install --save-dev @angular-devkit/build-angular
Run Code Online (Sandbox Code Playgroud)

更新!

你忘记添加RUN npm install到 docker 文件中

FROM node:10.12.0
RUN mkdir usr/src/app
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
RUN npm install -g @angular/cli@latest
COPY . .
EXPOSE 4200
CMD ng serve --host 0.0.0.0
Run Code Online (Sandbox Code Playgroud)