简体   繁体   中英

Angular in docker with lerna not building

I'm trying to deploy a single Angular client from my lerna monorepo via docker.

For this I created the following Docker file.

# Build environment
FROM node:12.2.0-alpine as build

# Work dir
WORKDIR /usr/src/app

# Set env values
ENV LOG_LEVEL=debug
ENV NODE_ENV=production

# Add lerna
COPY package.json .
COPY lerna.json .
RUN npm i lerna @angular/cli -g --loglevel notice

# Copy packages
COPY packages/client ./packages/client

# bootstrap
RUN yarn install --production --no-optional
RUN lerna bootstrap --scope=@proj/client -- --production --no-optional

# build
RUN lerna run build:prod --scope=@proj/client

# Run environment
FROM nginx:1.16.0-alpine
COPY --from=build ./packages/client/dist/client /usr/share/nginx/html
COPY --from=build ./packages/client/.nginx/nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

But when running docker build -t test -f packages/client/Dockerfile . it gives me following error:

lerna notice cli v3.22.1
lerna notice filter including "@proj/client"
lerna info filter [ '@proj/client' ]
lerna info Executing command in 1 package: "yarn run build:prod"
lerna ERR! yarn run build:prod exited 127 in '@proj/client'
lerna ERR! yarn run build:prod stdout:
yarn run v1.15.2
$ ng build --prod
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

lerna ERR! yarn run build:prod stderr:
An unhandled exception occurred: Cannot find module '@angular-devkit/build-angular/package.json'
Require stack:
- /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/architect/node/node-modules-architect-host.js
- /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/architect/node/index.js
- /usr/local/lib/node_modules/@angular/cli/models/architect-command.js
- /usr/local/lib/node_modules/@angular/cli/commands/build-impl.js
- /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/tools/export-ref.js
- /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/tools/index.js
- /usr/local/lib/node_modules/@angular/cli/utilities/json-schema.js
- /usr/local/lib/node_modules/@angular/cli/models/command-runner.js
- /usr/local/lib/node_modules/@angular/cli/lib/cli/index.js
- /usr/local/lib/node_modules/@angular/cli/lib/init.js
- /usr/local/lib/node_modules/@angular/cli/bin/ng
See "/tmp/ng-OFgChe/angular-errors.log" for further details.
error Command failed with exit code 127.

I've tried several combinations of the #bootstrap block:

  • I've tried with and without the yarn install
  • I've tried removing the --production and --no-optional flags
  • I've tried moving the devDependencies to the root package.json

Running these commands local (on a cleaned working folder) works perfectly, but each one of them gives me the same result in my docker build. So it's not that the @angular-devkit isn't listed as dependecy

Anybody got any clue on how to resolve this?

Found out how to resolve it. Apparently with or without the --production didn't matter for yarn

changing it to --production=false or changing the NODE_ENV to something else fixes the issue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM