I found many answers online to the exception Cannot find module '@angular-devkit/build-angular/package.json, among which adding @angular-devkit/[email protected] --force
, but none worked in my case.
Problem
Running an Angular application using docker-compose: after building the application, the error below occurs when running docker-compose up
; note, the app compiles successfully when running docker run <image>
, but I need it to work with Docker Compose.
defuse-ui | An unhandled exception occurred: Cannot find module '@angular-devkit/build-angular/package.json'
defuse-ui | Require stack:
defuse-ui | - /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/architect/node/node-modules-architect-host.js
defuse-ui | - /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/architect/node/index.js
defuse-ui | - /usr/local/lib/node_modules/@angular/cli/models/architect-command.js
defuse-ui | - /usr/local/lib/node_modules/@angular/cli/commands/serve-impl.js
defuse-ui | - /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/tools/export-ref.js
defuse-ui | - /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/tools/index.js
defuse-ui | - /usr/local/lib/node_modules/@angular/cli/utilities/json-schema.js
defuse-ui | - /usr/local/lib/node_modules/@angular/cli/models/command-runner.js
defuse-ui | - /usr/local/lib/node_modules/@angular/cli/lib/cli/index.js
defuse-ui | - /usr/local/lib/node_modules/@angular/cli/lib/init.js
defuse-ui | - /usr/local/lib/node_modules/@angular/cli/bin/ng
defuse-ui | See "/tmp/ng-nVUdCb/angular-errors.log" for further details.
defuse-ui exited with code 127
Dockerfile
FROM node:14.16.1
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json /app/package.json
RUN npm install -g @angular/[email protected] @angular-devkit/[email protected] --force
RUN npm install
COPY . /app
CMD ng serve --host 0.0.0.0 --port 4200
package.json
, package-lock.json
and other files are accessible at https://github.com/radon-h2020/radon-defuse/tree/905d7a339a31bc68dbd9b7a5258b5e9b19e65c68 release 1.0.0
Versions:
- Docker version 20.10.17, build 100c701
- docker-compose version 1.29.2, build unknown
CodePudding user response:
In package.json:
Instead of
"@angular/cli": "1.6.0",
change it to
"@angular/cli": "^1.6.0",
Or, in front of particular version of your local machine, add "^".
Then run this command:
npm update
npm update -g @angular/cli
CodePudding user response:
2 possible solutions:
Uninstall/remove node_modules and install again:
npm install -g @angular/cli@11
npm install @angular-devkit/[email protected]
Remove this line in docker-compose.yml:
angular-ayaresa: build: context: build/angular ports: - "4200:4200" volumes: - ../source/angular:/usr/src/app/ - /usr/src/app/node_modules/ // -- remove this line container_name: angular-ayaresa networks: - ayaresa-network