【发布时间】:2021-09-25 22:17:34
【问题描述】:
我正在尝试使用 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
我的码头文件:
# 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 audit fix 来解决几个问题,我已经删除了 node_modules 文件夹、缓存和 package-lock.json,并重新安装,但似乎没有任何帮助。
提前致谢。
【问题讨论】:
-
在
RUN npm install之后将所有内容复制到您的工作目录COPY . . -
根据输出问题是
inputField这是什么?你在本地有那个文件吗? -
@JasonWhite 如果您之前没有 COPY,那么 npm install 将找不到 package.json,因为 /app 目录将为空
-
InputField 是一个普通的 .ts 类,位于其他模型中。该特定行来自 index.ts
-
你有
.dockerignore文件吗?如果有,里面有什么?如果你注释掉RUN npm install和docker run --rm ... bash生成的图像之后的所有内容,你的源文件在那里吗?
标签: node.js angular docker nginx npm