npm 错误 TAR_BAD_ARCHIVE:无法识别的存档格式

问题描述 投票:0回答:1

我正在从角度代码构建 docker 图像。下面是我的 Dockerfile。

FROM node:22-slim AS build

WORKDIR /app
RUN rm -rf node_modules package-lock.json && npm cache clean --force && npm cache verify
RUN npm install -g npm@latest && npm install -g @angular/cli@latest
COPY package*.json /app/
RUN npm install
COPY ./ /app/
RUN ng build --configuration=production


FROM nginx:alpine

COPY --from=build /app/dist/test/browser /usr/share/nginx/html
COPY --from=build /app/dist/test/server /usr/share/nginx/server

COPY ./nginx.conf /etc/nginx/conf.d/default.conf
COPY ./nginx-found.conf /etc/nginx/extra-conf.d/backend-found.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

我面临这样的问题

=> ERROR [build 6/8] RUN npm install                                                                                                                               19.6s
------                                                                                                                                                                    
 > [build 6/8] RUN npm install:                                                                                                                                           
4.133 npm warn deprecated [email protected]: Rimraf versions prior to v4 are no longer supported                                                                               
5.478 npm warn deprecated [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
5.501 npm warn tar TAR_BAD_ARCHIVE: Unrecognized archive format
5.643 npm warn deprecated [email protected]: Glob versions prior to v9 are no longer supported
5.851 npm warn tar TAR_BAD_ARCHIVE: Unrecognized archive format
6.746 npm warn deprecated [email protected]: Ownership of Critters has moved to the Nuxt team, who will be maintaining the project going forward. If you'd like to keep using Critters, please switch to the actively-maintained fork at https://github.com/danielroe/beasties
**19.46 npm error code TAR_BAD_ARCHIVE
19.46 npm error TAR_BAD_ARCHIVE: Unrecognized archive format**
19.46 npm error A complete log of this run can be found in: /root/.npm/_logs/2024-12-17T12_38_08_326Z-debug-0.log
------
Dockerfile:7
--------------------
   5 |     RUN npm install -g npm@latest && npm install -g @angular/cli@latest
   6 |     COPY package*.json /app/
   7 | >>> RUN npm install
   8 |     COPY ./ /app/
   9 |     RUN ng build --configuration=production
--------------------
ERROR: failed to solve: process "/bin/sh -c npm install" did not complete successfully: exit code: 1

我使用的是ubuntu Linux系统。我尝试过 Windows wsl 和 ec2 linux。有时它可以工作并完成 docker 构建。但重大案件就到此为止了。

有什么建议请指导。

谢谢

angular docker dockerfile microservices angular18
1个回答
0
投票

Expected Behavior
应该安装这些软件包

原因可能是亚太地区的 NPM 注册表已关闭

我在步骤 npm install 时遇到了同样的问题

我在npm安装之前添加了RUN npm config set注册表https://registry.npmmirror.com/--global

Solution
运行 npm 配置集注册表 https://registry.npmmirror.com/ --global

它对我有用:)

© www.soinside.com 2019 - 2024. All rights reserved.