我正在尝试使用以下 docker 文件对我的 angular-cli 项目进行 dockerize:我确实遵循了以下步骤:
https://github.com/avatsaev/angular4-docker-example
---- docker 文件 ------
FROM nginx:1.13-alpine
ENV APP_PATH /app
ENV PATH $APP_PATH/node_modules/@angular/cli/bin/:$PATH
RUN apk add --update --no-cache nodejs && mkdir $APP_PATH && rm -rf /etc/nginx/conf.d/*
WORKDIR $APP_PATH
COPY . .
COPY nginx/default.conf /etc/nginx/conf.d/
ARG NPM_TOKEN
COPY .npmrc .npmrc
COPY package.json package.json
RUN npm install
ng build --aot --prod \
&& rm -rf /usr/share/nginx/html/* \
&& mv ./dist/* /usr/share/nginx/html/ \
&& npm cache clean \
&& apk del nodejs libstdc++ libgcc libuv http-parser ca-certificates \
&& rm -rf ./*
CMD ["nginx", "-g", "daemon off;"]
它下载软件包,正常运行 npm install 并且在“build ng build --aot --prod”上失败,
它成功下载了所有包,包括 typescript ,不知道为什么在这里失败,
我没有从异常中得到任何线索,这里有什么问题:
module.js:471
throw err;
^
Error: Cannot find module 'typescript'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/app/node_modules/@angular/cli/models/config/config.js:5:12)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
最佳答案
package.json 中的一个包是指私有(private)注册表,我的错误是我没有只为那个包标记私有(private)注册表,而是在我的 .npmrc 文件中进行了全局标记,看起来像
"registry=URl private registry"
应该是
"scope:registry=URL for private registry"
所以它正在从私有(private)注册表下载公共(public)包,由于某种原因没有按预期下载一些模块。这就是为什么我得到
Cannot find module 'typescript' error
.同时,我的 .npmrc 文件中的授权 token 由于多次重试而损坏,我不确定我必须如何删除文件并再次撤销 token 并重新执行
npm install
让它工作。以下链接包含有关 npm token 和下载 docker 私有(private)包的信息。如果有人遇到类似问题,我希望这会有所帮助。https://docs.npmjs.com/private-modules/ci-server-config
关于angular - Dockerize angular-cli 4 项目在尝试运行 "ng build --aot --prod"时失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44707913/