Reputation: 430
I tried to add my angular6 app in a docker-compose
environment. I created the project locally and it works, but after docker-compose build
and docker-compose up
, it send next error:
[email protected] start /usr/src/app
> ng serve --host 0.0.0.0 --disable-host-check -p 3000
Could not find module "@angular-devkit/build-angular" from "/usr/src/app".
Error: Could not find module "@angular-devkit/build-angular" from "/usr/src/app".
at Object.resolve (/usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/core/node/resolve.js:141:11)
at Observable.rxjs_1.Observable [as _subscribe] (/usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/architect/src/architect.js:132:40)
at Observable.subscribe (/usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/Observable.js:162:69)
at DoOperator.call (/usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/operators/tap.js:71:23)
at Observable.subscribe (/usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/Observable.js:159:22)
at /usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/util/subscribeTo.js:22:31
at Object.subscribeToResult (/usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/util/subscribeToResult.js:7:45)
at MergeMapSubscriber._innerSub (/usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/operators/mergeMap.js:132:38)
at MergeMapSubscriber._tryNext (/usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/operators/mergeMap.js:129:14)
at MergeMapSubscriber._next (/usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/operators/mergeMap.js:112:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `ng serve --host 0.0.0.0 --disable-host-check -p 3000`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
angular-ayaresa |
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-05-23T10_03_17_591Z-debug.log
This is my Angular Dockerfile :
# Create image based on the official Node 8.10.0 image from dockerhub
FROM node:8.10.0
# Create a directory where our app will be placed
RUN mkdir -p /usr/src/app
# Change directory so that our commands run inside this new directory
WORKDIR /usr/src/app
# Copy dependency definitions
COPY ./quickstart /usr/src/app
# Install dependecies
RUN rm -rf node_modules/
RUN npm i --save
RUN npm i npm@latest -g
RUN npm install -g @angular/cli
# Expose the port the app runs in
EXPOSE 4200
# Serve the app
CMD ["npm", "start"]
The module @angular-devkit/build-angular
was correctly installed and included in package.json
Upvotes: 1
Views: 2685
Reputation: 430
I found the problem.
I have removed a line in my docker-compose.yml.
angular-ayaresa:
build:
context: build/angular
ports:
- "4200:4200"
volumes:
- ../source/angular:/usr/src/app/
- /usr/src/app/node_modules/ // <-- this line
container_name: angular-ayaresa
networks:
- ayaresa-network
This line allow container to ignore a folder in volume.
The problem was that the node_modules
was included in volumes and Angular
searched module "@angular-devkit/build-angular"
from local node_modules
and not in it container node_modules
.
I just add ignore node_modules and problem was solved.
Upvotes: 1
Reputation: 985
You have an error in your docker file you did a WORKDIR and set it to /usr/src/app
This means that, context will be switched to that file.
So when you do COPY ./quickstart /usr/src/app
, this should be COPY ./quickstart .
The docker documentation says
The <src> path must be inside the context of the build; you cannot COPY ../something /something, because the first step of a docker build is to send the context directory (and subdirectories) to the docker daemon.
ref: https://docs.docker.com/engine/reference/builder/#copy
Upvotes: 1