【问题标题】:Angular in docker with lerna not buildingdocker中的角度与lerna没有建立
【发布时间】:2020-10-27 19:03:29
【问题描述】:

我正在尝试通过 docker 从我的 lerna monorepo 部署单个 Angular 客户端。

为此,我创建了以下 Docker 文件。

# 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;"]

但是在运行docker build -t test -f packages/client/Dockerfile . 时会出现以下错误:

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.

我尝试了几种#bootstrap 块的组合:

  • 我尝试过使用和不使用yarn install
  • 我已尝试删除 --production--no-optional 标志
  • 我尝试将devDependencies 移动到根package.json

在本地(在已清理的工作文件夹上)运行这些命令可以完美运行,但在我的 docker 构建中,它们中的每一个都给了我相同的结果。所以并不是@angular-devkit 没有被列为依赖项

有人知道如何解决这个问题吗?

【问题讨论】:

    标签: angular docker lerna


    【解决方案1】:

    了解如何解决它。 显然有或没有--productionyarn 来说并不重要

    将其更改为 --production=false 或将 NODE_ENV 更改为其他内容可以解决问题

    【讨论】:

      猜你喜欢
      • 2021-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-09
      相关资源
      最近更新 更多