在生产中部署Angular App-获取不同的CLI版本

时间:2018-12-10 15:31:05

标签: angular typescript jenkins dockerfile

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

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

我也收到错误消息:angular/compiler-cli@7.1.2需要typescript @'> = 3.1.1 <3.2',但是找到了3.2.2。 -> fyi:我已经在dockerfile中安装了RUN npm install typescript@3.1.6,它也可以安装(我可以在jenkins控制台中看到)。

package.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

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:1)

您已定义的“ angular-cli”软件包版本不是严格的,而是支持自动升级到最大主要更新的最新版本:“ @angular/cli": "^7.0.5”。

只需指定严格,不带“ ^”:“ @angular/cli": "7.0.5