社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  docker

带有angular和nginx的Dockerfile在构建阶段失败

bass • 3 年前 • 1343 次点击  

我正在尝试使用angular和nginx为我的项目构建docker映像,但在构建阶段尝试装载映像时出现以下错误(安装似乎可以正常工作):

#11 103.1 Error: src/app/models/index.ts:5:28 - error TS2307: Cannot find module './inputField' or its corresponding type declarations.
#11 103.1
#11 103.1 5 export { InputField } from './inputField';
#11 103.1                              ~~~~~~~~~~~~~~
#11 103.1
#11 103.1
#11 103.1
#11 103.1 npm ERR! code ELIFECYCLE
#11 103.1 npm ERR! errno 1
#11 103.2 npm ERR! myproject@11.0.0 build: `ng build --build-optimizer --output-hashing=none`
#11 103.2 npm ERR! Exit status 1
#11 103.2 npm ERR!
#11 103.2 npm ERR! Failed at the myproject@11.0.0 build script.
#11 103.2 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
#11 103.2
#11 103.2 npm ERR! A complete log of this run can be found in:
#11 103.2 npm ERR!     /root/.npm/_logs/2021-07-17T10_12_55_066Z-debug.log
------
executor failed running [/bin/sh -c npm run build]: exit code: 1

我的dockerfile:

# Angular image
FROM node:latest as build

WORKDIR /app
COPY . .
RUN npm install 
RUN npm run build

# Nginx image
FROM nginx:latest

COPY --from=build /dist/angular/ /usr/share/nginx/html/

EXPOSE 80

我做了npm审计修复来解决几个问题,并且删除了node_modules文件夹、缓存和包锁。json,并再次安装,但这些似乎都没有帮助。

提前谢谢。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/130586
 
1343 次点击  
文章 [ 2 ]  |  最新文章 3 年前
Jahnavi Paliwal Md. Saiful Isl
Reply   •   1 楼
Jahnavi Paliwal Md. Saiful Isl    3 年前

试试跑步 ng build InputField .

export { InputField } from './inputField';
Robert
Reply   •   2 楼
Robert    3 年前

根据原版:

error TS2307: Cannot find module './inputField'

从重命名文件 InputField.ts inputField.ts 解决了容器内部构建的问题。

查看构建容器内部:

只运行一个构建容器是@David Maze的一个很好的评论

比如:

$ docker run --rm -it <name_of_the_container> /bin/bash

这样你就可以发布 npm run build 命令,看看里面发生了什么。

我还建议大家洗个澡 ng new ngApp 作为参考。 如果该应用程序可以构建,那么问题就出在其他方面,而不是 Dockerfile .

样本:

# Angular build image
FROM node:latest as builder

WORKDIR /app
COPY . .
RUN npm install
RUN npm run build


# Nginx image
FROM nginx:latest

COPY --from=builder /app/dist/ngApp /usr/share/nginx/html/

EXPOSE 80