我注意到在转角项目中有几个错误,而在运行ng serve
或npm run build
命令时没有出现错误。话虽如此,我还是在tsconfig.json文件中设置了tsconfig.json。
我将这个命令用于:
docker build -t myProject:latest .
文档:
#stage 1
FROM node:16.15.0 as node
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build
#stage 2
FROM nginx:alpine
COPY --from=node /app/dist/myProject /usr/share/nginx/html
我可以说,我的项目中的每个组件和模块都有错误,例如:
error NG8001: 'mat-paginator' is not a known element:
error NG6002: Appears in the NgModule.imports of AppModule, but itself has errors
error NG8003: No directive found with exportAs 'ngForm'.
error NG8002: Can't bind to 'pageSizeOptions' since it isn't a known property of 'mat-paginator'.
error NG8002: Can't bind to 'length' since it isn't a known property of 'mat-paginator'.
error NG8002: Can't bind to 'label' since it isn't a known property of 'app-text-input'.
以下是错误出现之前的最新输出:
所有版本:
Angular CLI: 13.3.7
Node: 16.15.0
Package Manager: npm 8.5.5
OS: win32 x64
Angular: 13.3.10
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1303.7
@angular-devkit/build-angular 13.3.7
@angular-devkit/core 13.3.7
@angular-devkit/schematics 13.3.7
@angular/cdk 13.3.7
@angular/cli 13.3.7
@angular/material 13.3.7
@schematics/angular 13.3.7
rxjs 6.6.7
typescript 4.6.4
更新:
我已经将.dockerignore
放在与node_modules
相同的目录中的项目根目录中。
.dockerignore:
node_modules
.angular
发布于 2022-05-26 23:46:05
TL;DR:不要在主机和容器之间共享node_modules
看起来你的node_modules
会引起麻烦。Docker在Linux容器中运行,而您的机器可能有另一个操作系统。但是,有些包包含特定操作系统(即node-sass
)的编译代码,这些代码不能在不同的操作系统之间共享。在当前的设置中,主机的node_modules
被复制到容器中。
要解决此问题,请将一个.dockerignore
文件添加到DOCKERFILE
所在的目录中,内容如下:
node_modules
这将停止将node_modules
从主机复制到容器中。此外,我建议使用npm ci
而不是npm install
。
https://stackoverflow.com/questions/72401585
复制