当尝试在Docker中构建Ionic/Angular应用程序时,出现“错误:无法找到模块- ng”

kzipqqlq  于 2023-05-05  发布在  Ionic
关注(0)|答案(1)|浏览(208)

重现错误的步骤:
版本:

Angular CLI: 15.2.7
Node: 16.18.0
Package Manager: pnpm 8.4.0
Ionic: 7.1.1
Docker version 23.0.5, build bc4487a

将ionic配置为使用pnpm:

ionic config set -g npmClient pnpm

创建应用程序:

ionic start myApp tabs --capacitor

添加以下Dockerfile:

FROM node:latest as build
WORKDIR /usr/local/app
COPY ./ /usr/local/app/
SHELL ["/bin/bash", "-c"]
RUN npm install --global pnpm \
    && SHELL=bash pnpm setup \
    && source /root/.bashrc
ENV PNPM_HOME="/root/.local/share/pnpm"
ENV PATH="${PATH}:${PNPM_HOME}"
RUN pnpm install -g @angular/cli
RUN pnpm install -g @ionic/cli
RUN ionic config set -g npmClient pnpm
RUN pnpm install
RUN pnpm run build

FROM nginx:latest
COPY --from=build /usr/local/app/www usr/share/nginx/html
EXPOSE 80

运行:

docker build --pull --rm -f "Dockerfile" -t myapp:latest "."

这是我的错误:

> [build 9/9] RUN pnpm run build:
#0 0.807
#0 0.807 > MyApp@0.0.1 build /usr/local/app
#0 0.807 > ng build
#0 0.807
#0 0.828 node:internal/modules/cjs/loader:1085
#0 0.828   throw err;
#0 0.828   ^
#0 0.828
#0 0.828 Error: Cannot find module '/usr/local/app/node_modules/@angular/cli/bin/ng.js'
#0 0.828     at Module._resolveFilename (node:internal/modules/cjs/loader:1082:15)
#0 0.828     at Module._load (node:internal/modules/cjs/loader:928:27)
#0 0.828     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
#0 0.828     at node:internal/main/run_main_module:23:47 {
#0 0.828   code: 'MODULE_NOT_FOUND',
#0 0.828   requireStack: []
#0 0.828 }
#0 0.828
#0 0.828 Node.js v20.0.0
#0 0.833  ELIFECYCLE  Command failed with exit code 1.
------
Dockerfile:25
--------------------
  23 |     RUN pnpm install
  24 |     # Generate the build of the app
  25 | >>> RUN pnpm run build
  26 |
  27 |     # 2. Serve app
--------------------
ERROR: failed to solve: process "/bin/bash -c pnpm run build" did not complete successfully: exit code: 1

有趣的是,整个应用程序昨天构建得很好。可能是一个docker/angular bug?

txu3uszq

txu3uszq1#

这个问题似乎是因为一个有缺陷的pnpm版本。降级到pnpm@latest-7(而不是8.4.0)解决了这个问题

相关问题