首页 > 解决方案 > Angular 应用程序在生产中部署 - 获取不同的 cli 版本

问题描述

我正在尝试在 Jenkins 中部署我的 Angular 应用程序。我正在使用 Jenkins 和 Docker 在生产环境中构建和部署。

我的 package.json 有 angular/compiler-cli: 7.0.3,但我在 jenkins 控制台中看到它说 7.1.2。谁能帮我理解为什么它不同?

我也收到错误: angular/compiler-cli@7.1.2 requires typescript@'>=3.1.1 <3.2' 但找到了 3.2.2。-> 仅供参考:我的 dockerfile 中已经有 RUN npm install typescript@3.1.6 并且它也可以安装(我可以在 jenkins 控制台中看到)。

包.json:

  "dependencies": {
    "@angular/cdk": "^7.0.4",
    "@angular/common": "^7.0.3",
    "@angular/compiler": "^7.0.3",
    "@angular/core": "^7.0.3",
    "@angular/forms": "^7.0.3",
    "@angular/http": "^7.0.3",
    . . .
    . . .
    . . .
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.10.3",
    "@angular/cli": "^7.0.5",
    "@angular/compiler-cli": "^7.0.3",
    . . .
    . . .
    . . .
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "^3.1.6"
  }

Dockerfile:

# ---- Base Node ----
# FROM node:carbon AS base
FROM tiangolo/node-frontend:10 as build-stage
# Create app directory
WORKDIR /app

# ---- Dependencies ----
# FROM base AS dependencies  
# A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY package*.json /app/
# install app dependencies including 'devDependencies'
RUN npm install
RUN npm install angular -g
RUN npm install typescript@3.1.6
#RUN ng update
#RUN npm update

# ---- Copy Files/Build ----


COPY ./ /app/
ARG configuration=production
RUN npm run build -- --output-path=./dist/out --configuration $configuration

Jenkins 控制台中的错误:

Step 3/12 : COPY package*.json /app/
 ---> c58c4341ccf1
Step 4/12 : RUN npm install
 ---> Running in b779f562e7d1

> node-sass@4.9.3 install /app/node_modules/node-sass
> node scripts/install.js

Downloading binary from https://github.com/sass/node-sass/releases/download/v4.9.3/linux-x64-64_binding.node
Download complete
Binary saved to /app/node_modules/node-sass/vendor/linux-x64-64/binding.node
Caching binary to /root/.npm/node-sass/4.9.3/linux-x64-64_binding.node

> node-sass@4.9.3 postinstall /app/node_modules/node-sass
> node scripts/build.js

Binary found at /app/node_modules/node-sass/vendor/linux-x64-64/binding.node
Testing binary
Binary is fine

> angular-ide@0.9.55 postinstall /app/node_modules/angular-ide
> node ./scripts/post.js

[91mnpm WARN[0m[91m lifecycle iqs-web@0.0.0~postinstall: cannot run in wd iqs-web@0.0.0 node patch.js (wd=/app)
[0m[91mnpm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

[0madded 1266 packages from 1241 contributors, removed 8 packages, updated 7 packages and audited 50062 packages in 53.101s
found 0 vulnerabilities

Removing intermediate container b779f562e7d1
 ---> 853256b9e94a
Step 5/12 : RUN npm install angular -g
 ---> Running in 377f5b1fb516
+ angular@1.7.5
added 1 package from 1 contributor in 0.659s
Removing intermediate container 377f5b1fb516
 ---> a18cf57ae160
Step 6/12 : RUN npm install typescript@3.1.6
 ---> Running in 0fad7871d368
[91mnpm WARN[0m[91m @angular/service-worker@6.1.10 requires a peer of @angular/core@6.1.10 but none is installed. You must install peer dependencies yourself.
[0m[91mnpm [0m[91mWARN @angular/service-worker@6.1.10 requires a peer of @angular/common@6.1.10 but none is installed. You must install peer dependencies yourself.
[0m[91mnpm [0m[91mWARN angular5-csv@0.2.10 requires a peer of @angular/core@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm [0m[91mWARN angular5-csv@0.2.10 requires a peer of @angular/http@^5.0.0 but none is installed. You must install peer dependencies yourself.
[0m[91mnpm WARN[0m[91m angular5-csv@0.2.10 requires a peer of rxjs@^5.5.2 but none is installed. You must install peer dependencies yourself.
npm[0m[91m WARN ng2-smart-table@1.3.5 requires a peer of @angular/common@^6.0.1 but none is installed. You must install peer dependencies yourself.
[0m[91mnpm WARN[0m[91m ng2-smart-table@1.3.5 requires a peer of @angular/core@^6.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN[0m[91m ng2-smart-table@1.3.5 requires a peer of @angular/forms@^6.0.1 but none is installed. You must install peer dependencies yourself.
[0m[91mnpm [0m[91mWARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
npm[0m[91m WARN notsup[0m[91m SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
[0m[91m
[0m+ typescript@3.1.6
updated 1 package and audited 50062 packages in 12.661s
found 0 vulnerabilities

Removing intermediate container 0fad7871d368
 ---> 90d01e19e304
Step 7/12 : COPY ./ /app/
Resuming build at Mon Dec 10 09:05:56 CST 2018 after Jenkins restart
Waiting to resume part of IQS-WEB #12: ???
Ready to run at Mon Dec 10 09:06:08 CST 2018
 ---> f640df25e979
Step 8/12 : ARG configuration=production
 ---> Running in f71224f70ead
Removing intermediate container f71224f70ead
 ---> e276ace419a8
Step 9/12 : RUN npm run build -- --output-path=./dist/out --configuration $configuration
 ---> Running in 70e25196b650

> iqs-web@0.0.0 build /app
> ng build "--output-path=./dist/out" "--configuration" "production"

[91m
@angular/compiler-cli@7.1.2 requires typescript@'>=3.1.1 <3.2' but 3.2.2 was found instead.
Using this version can result in undefined behaviour and difficult to debug problems.

Please run the following command to install a compatible version of TypeScript.

    npm install typescript@">=3.1.1 <3.2"

To disable this warning run "ng config cli.warnings.typescriptMismatch false".

[0m
Date: 2018-12-10T15:06:44.098Z
Hash: dad34d5f1324a7bda1cb
Time: 7418ms
chunk {scripts} scripts.08fbed0cc1e97e0c177b.js (scripts) 142 kB  [rendered]
chunk {0} runtime.ec2944dd8b20ec099bf3.js (runtime) 1.41 kB [entry] [rendered]
chunk {1} main.9868d9b237c3a48c54da.js (main) 128 bytes [initial] [rendered]
chunk {2} polyfills.85f47f0bf59079cbc23a.js (polyfills) 130 bytes [initial] [rendered]
chunk {3} styles.ec522b2ad67e374b5ac2.css (styles) 157 kB [initial] [rendered]
[91m
ERROR in The Angular Compiler requires TypeScript >=3.1.1 and <3.2.0 but 3.2.2 was found instead.
[0m[91mnpm ERR! code ELIFECYCLE
[0m[91mnpm ERR! errno 1

标签: angulartypescriptjenkinsdockerfile

解决方案


package.json 中 typescript 的版本是"typescript": "^3.1.6". 这意味着它将使用最新的主要版本(xyz 中的第二个数字),并且它使用3.2.2, 作为控制台错误状态。^从打字稿版本中删除。


推荐阅读