在生产中部署 Angular 应用程序 - 获取不同的 cli 版本

标签 angular typescript jenkins dockerfile

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

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

我还收到错误: Angular/[email protected]需要 typescript@'>=3.1.1 <3.2' 但找到了 3.2.2。 -> 仅供引用:我已经 RUN npm install [email protected]在我的 dockerfile 中,它也会安装(我可以在 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 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="601419100513031209101420534e514e56" rel="noreferrer noopener nofollow">[email protected]</a>
#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

> <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="eb85848f8ec6988a9898abdfc5d2c5d8" rel="noreferrer noopener nofollow">[email protected]</a> 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

> <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c4aaaba0a1e9b7a5b7b784f0eafdeaf7" rel="noreferrer noopener nofollow">[email protected]</a> 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

> <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f5949b9280999487d89c9190b5c5dbccdbc0c0" rel="noreferrer noopener nofollow">[email protected]</a> postinstall /app/node_modules/angular-ide
> node ./scripts/post.js

[91mnpm WARN[0m[91m lifecycle <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c2abb3b1efb5a7a082f2ecf2ecf2" rel="noreferrer noopener nofollow">[email protected]</a>~postinstall: cannot run in wd <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2d445c5e005a484f6d1d031d031d" rel="noreferrer noopener nofollow">[email protected]</a> node patch.js (wd=/app)
[0m[91mnpm WARN optional SKIPPING OPTIONAL DEPENDENCY: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2442574152414a505764150a160a10" rel="noreferrer noopener nofollow">[email protected]</a> (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f294819784979c8681b2c3dcc0dcc6" rel="noreferrer noopener nofollow">[email protected]</a>: 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
+ <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0d6c636a78616c7f4d3c233a2338" rel="noreferrer noopener nofollow">[email protected]</a>
added 1 package from 1 contributor in 0.659s
Removing intermediate container 377f5b1fb516
 ---> a18cf57ae160
Step 6/12 : RUN npm install <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="45313c35203626372c353105766b746b73" rel="noreferrer noopener nofollow">[email protected]</a>
 ---> Running in 0fad7871d368
[91mnpm WARN[0m[91m @angular/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a2d1c7d0d4cbc1c78fd5cdd0c9c7d0e2948c938c9392" rel="noreferrer noopener nofollow">[email protected]</a> requires a peer of @angular/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0d6e627f684d3b233c233c3d" rel="noreferrer noopener nofollow">[email protected]</a> but none is installed. You must install peer dependencies yourself.
[0m[91mnpm [0m[91mWARN @angular/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="74071106021d171159031b061f110634425a455a4544" rel="noreferrer noopener nofollow">[email protected]</a> requires a peer of @angular/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="81e2eeececeeefc1b7afb0afb0b1" rel="noreferrer noopener nofollow">[email protected]</a> but none is installed. You must install peer dependencies yourself.
[0m[91mnpm [0m[91mWARN <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="74151a1301181506415917070234445a465a4544" rel="noreferrer noopener nofollow">[email protected]</a> requires a peer of @angular/core@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm [0m[91mWARN <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f0919e97859c9182c5dd938386b0c0dec2dec1c0" rel="noreferrer noopener nofollow">[email protected]</a> requires a peer of @angular/http@^5.0.0 but none is installed. You must install peer dependencies yourself.
[0m[91mnpm WARN[0m[91m <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d5b4bbb2a0b9b4a7e0f8b6a6a395e5fbe7fbe4e5" rel="noreferrer noopener nofollow">[email protected]</a> requires a peer of rxjs@^5.5.2 but none is installed. You must install peer dependencies yourself.
npm[0m[91m WARN <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9cf2fbaeb1eff1fdeee8b1e8fdfef0f9dcadb2afb2a9" rel="noreferrer noopener nofollow">[email protected]</a> requires a peer of @angular/common@^6.0.1 but none is installed. You must install peer dependencies yourself.
[0m[91mnpm WARN[0m[91m <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fa949dc8d789979b888ed78e9b98969fbacbd4c9d4cf" rel="noreferrer noopener nofollow">[email protected]</a> requires a peer of @angular/core@^6.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN[0m[91m <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b7d9d0859ac4dad6c5c39ac3d6d5dbd2f78699849982" rel="noreferrer noopener nofollow">[email protected]</a> 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: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="563025332033382225166778647862" rel="noreferrer noopener nofollow">[email protected]</a> (node_modules/fsevents):
npm[0m[91m WARN notsup[0m[91m SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e482978192818a9097a4d5cad6cad0" rel="noreferrer noopener nofollow">[email protected]</a>: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
[0m[91m
[0m+ <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="15616c65706676677c656155263b243b23" rel="noreferrer noopener nofollow">[email protected]</a>
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

> <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7f160e0c52081a1d3f4f514f514f" rel="noreferrer noopener nofollow">[email protected]</a> build /app
> ng build "--output-path=./dist/out" "--configuration" "production"

[91m
@angular/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f5969a98859c999087d896999cb5c2dbc4dbc7" rel="noreferrer noopener nofollow">[email protected]</a> 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

最佳答案

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

关于在生产中部署 Angular 应用程序 - 获取不同的 cli 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53708798/

相关文章:

javascript - 行为主题 : next is not a function

javascript - 在 setter 中使用带有类型保护的 getter 和 setter

typescript - 从 Flow 迁移到 Typescript : $Keys equivalent in TS?

php - Jenkins(使用Ant)未执行PHPUnit测试

hudson - 使用 Hudson/Jenkins API 确定给定作业当前是否正在运行

angular - 如何以 react 形式获取 radio 的选定值

angular - Angular 2 不透明 token 中有什么,有什么意义?

angular - 将参数传递给组件。是否使用括号

generics - 如何在Typescript中参数化函数参数元组

jenkins - 在 Jenkins 中将文件从一个目录复制到另一个目录