【发布时间】:2020-10-01 01:03:37
【问题描述】:
我正在尝试在自定义图像中构建新的 Angular 9 项目(基于官方节点图像)。基本上我想缓存包构建而不是角度源构建。
下面是我的 Dockerfile
FROM node
COPY package.json /mnt/
RUN cd /mnt/ && npm install && npm audit fix && npm install -g @angular/cli
ENV PATH /mnt/node_modules/.bin:$PATH
RUN mkdir /mnt/project
WORKDIR /mnt/project
ENTRYPOINT ["/bin/bash", "run.sh"]
我创建了新的 angular 9 项目,我复制了上面的 docker 文件和 run.sh 文件(稍后描述),并创建了图像 angular-cache-image。我还更新了 node_module 目录路径的 angular.json 和 tsconfig.json 文件(将 node_modules 替换为 ../node_modules)。我已经从本地项目目录中删除了 dist 和 node_modules 目录。
现在我运行容器并将挂载绑定到容器位置 /mnt/project 并在入口点内运行构建命令。 (请注意,在容器中,node_modules 不在 Angular 项目目录中)
docker container run -it --rm --name angular-cache-test -v $(pwd):/mnt/project --user $(id -u):$(id -g) angular-cache-image
run.sh 目前只有 build 命令(以后做更多的事情)
#!/bin/bash
npm -v
node -v
ng build --prod
但是我遇到了以下错误
6.13.7
v13.10.1
ERROR in ../node_modules/@angular/platform-browser/platform-browser.d.ts:44:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.
This likely means that the library (@angular/platform-browser) which declares BrowserModule has not been processed correctly by ngcc, or is not compatible with Angular Ivy. Check if a newer version of the library is available, and update if so. Also consider checking with the library's authors to see if the library is expected to be compatible with Ivy.
44 export declare class BrowserModule {
~~~~~~~~~~~~~
以下是我的本地机器角度版本详情:
Angular CLI: 9.0.2
Node: 12.18.0
OS: linux x64
Angular: <error>
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.900.2 (cli-only)
@angular-devkit/build-angular <error>
@angular-devkit/core 9.0.2 (cli-only)
@angular-devkit/schematics 9.0.2 (cli-only)
@schematics/angular 9.0.2 (cli-only)
@schematics/update 0.900.2 (cli-only)
rxjs 6.5.3 (cli-only)
typescript <error>
本地 npm 版本为 6.14.4
我尝试通过禁用 ivy 编译来解决问题,但无法解决。感谢有人可以帮助我解决这个问题?
【问题讨论】: