Angular 6 Docker Build - Angular 编译器中的错误需要 TypeScript >=2.7.2 和 <2.8.0,但找到的是 2.8.3
Posted
技术标签:
【中文标题】Angular 6 Docker Build - Angular 编译器中的错误需要 TypeScript >=2.7.2 和 <2.8.0,但找到的是 2.8.3【英文标题】:Angular 6 Docker Build - ERROR in The Angular Compiler requires TypeScript >=2.7.2 and <2.8.0 but 2.8.3 was found instead 【发布时间】:2018-11-02 09:20:54 【问题描述】:我正在为我的 Angular 项目创建一个 docker 映像。
在 package.json 中它引用 "typescript": "^2.7.2"
我运行docker build -t demo:production .
并收到以下错误:
ERROR in The Angular Compiler requires TypeScript >=2.7.2 and <2.8.0 but 2.8.3 was found instead.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! demo@0.0.0 build: `ng build "--configuration" "production"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the demo@0.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-05-23T11_16_37_049Z-debug.log
package.json
"name": "demo",
"version": "0.0.0",
"license": "MIT",
"scripts":
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
,
"private": true,
"dependencies":
"@angular/animations": "^6.0.0",
"@angular/cdk": "^6.0.0",
"@angular/common": "^6.0.0",
"@angular/compiler": "^6.0.0",
"@angular/core": "^6.0.0",
"@angular/flex-layout": "^6.0.0-beta.15",
"@angular/forms": "^6.0.0",
"@angular/http": "^6.0.0",
"@angular/material": "^6.0.0",
"@angular/platform-browser": "^6.0.0",
"@angular/platform-browser-dynamic": "^6.0.0",
"@angular/router": "^6.0.0",
"@auth0/angular-jwt": "^2.0.0",
"@types/chartjs": "0.0.31",
"@types/googlemaps": "^3.30.8",
"@types/lodash": "^4.14.108",
"auth0-js": "^9.5.1",
"auth0-lock": "^11.6.1",
"chart.js": "^2.7.2",
"chartjs-plugin-annotation": "^0.5.7",
"chartjs-plugin-datalabels": "^0.3.0",
"core-js": "^2.5.5",
"d3": "^5.1.0",
"font-awesome": "^4.7.0",
"hammerjs": "^2.0.8",
"json-formatter-js": "^2.2.0",
"lodash": "^4.17.10",
"lodash-es": "^4.17.10",
"moment": "^2.22.1",
"npm": "^6.0.0",
"progressbar.js": "^1.0.1",
"rxjs": "^6.1.0",
"rxjs-compat": "^6.1.0",
"ua-parser-js": "^0.7.18",
"wordcloud": "^1.1.0",
"zone.js": "^0.8.26"
,
"devDependencies":
"@angular-devkit/build-angular": "~0.6.0",
"@angular/cli": "^6.0.0",
"@angular/compiler-cli": "^6.0.0",
"@angular/language-service": "^6.0.0",
"@types/d3": "^5.0.0",
"@types/jasmine": "~2.8.7",
"@types/jasminewd2": "~2.0.3",
"@types/lodash-es": "^4.17.0",
"@types/node": "^10.0.4",
"codelyzer": "^4.3.0",
"eslint": "^4.19.1",
"jasmine-core": "~3.1.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.2",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^1.4.2",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^1.0.0",
"protractor": "~5.3.1",
"source-map-explorer": "^1.5.0",
"ts-node": "~6.0.3",
"tslint": "~5.10.0",
"typescript": "^2.7.2"
DockerFile
# Stage 0 - Pre-requisite: Based On Node.js to build and compile Demo Angular App.
FROM node:8.11.2 as node
WORKDIR /app
COPY package.json /app/
RUN npm install
COPY ./ /app/
ARG env=production
RUN npm run build -- --configuration $env
# Stage 1 - Based On nginx to have a compiled and production ready build.
FROM nginx:1.14
COPY --from=node /app/dist/ /usr/share/nginx/html
COPY ./nginx-custom.conf /etc/nginx/conf.d/default.conf
【问题讨论】:
将 ^2.7.2 更改为 ~2.7.2 然后 npm install。 @rrd 成功了 @rrd 谢谢,这应该被标记为正确答案。 【参考方案1】:Angular 6 需要 2.7.2 和 2.8.0 之间的 TypeScript 版本。
这就是它抛出错误的原因。
运行以下命令修复:
npm install typescript@2.7.2
或
您可以在package.json
中更改它,如下所示,然后再次运行npm install
。
【讨论】:
以上是关于Angular 6 Docker Build - Angular 编译器中的错误需要 TypeScript >=2.7.2 和 <2.8.0,但找到的是 2.8.3的主要内容,如果未能解决你的问题,请参考以下文章
错误:在 Angular CLI >6.0 中,Karma 插件现在由“@angular-devkit/build-angular”导出
Angular 6,在 ng build index.html 在控制台中出现错误之后
当我使用 ng build 时,proxy.conf.json 在 Angular 6 中不起作用
错误 TS1005:';'预期的。 TypeScript Angular 6 For First Build error rxjs inside node_modules