【问题标题】:Angular Image For Docker quitting With ErrorDocker 的 Angular 图像因错误而退出
【发布时间】:2019-05-24 16:02:30
【问题描述】:
Node Version that my docker image has = v12.3.0
NPM version = 6.9.0

下面是 package.json 文件,其中列出了应用程序的所有依赖项。

{
  ..
  },
  "private": true,
  "dependencies": {
    "@agm/core": "1.0.0-beta.5",
    "@angular/animations": "7.2.1",
    "@angular/cdk": "7.2.1",
    "@angular/common": "7.2.1",
    "@angular/compiler": "7.2.1",
    "@angular/core": "7.2.1",
    "@angular/flex-layout": "7.0.0-beta.23",
    "@angular/forms": "7.2.1",
    "@angular/http": "7.2.1",
    "@angular/material": "7.2.1",
    "@angular/material-moment-adapter": "7.2.1",
    "@angular/platform-browser": "7.2.1",
    "@angular/platform-browser-dynamic": "7.2.1",
    "@angular/router": "7.2.1",
    "@ngrx/effects": "7.1.0",
    "@ngrx/router-store": "7.1.0",
    "@ngrx/store": "7.1.0",
    "@ngrx/store-devtools": "7.1.0",
    "@ngx-translate/core": "11.0.1",
    "@swimlane/dragula": "3.7.3",
    "@swimlane/ngx-charts": "10.0.0",
    "@swimlane/ngx-datatable": "14.0.0",
    "@swimlane/ngx-dnd": "6.0.0",
    "@types/prismjs": "1.9.0",
    "angular-calendar": "0.26.4",
    "angular-in-memory-web-api": "0.8.0",
    "chart.js": "2.7.3",
    "ci": "1.0.0",
    "classlist.js": "1.1.20150312",
    "core-js": "2.6.2",
    "d3": "5.7.0",
    "date-fns": "1.30.1",
    "hammerjs": "2.0.8",
    "html2canvas": "1.0.0-alpha.12",
    "jspdf": "1.5.3",
    "jwt-decode": "2.2.0",
    "lodash": "4.17.11",
    "moment": "2.24.0",
    "ng2-charts": "1.6.0",
    "ngrx-store-freeze": "0.2.4",
    "ngx-clipboard": "11.1.9",
    "ngx-color-picker": "7.3.0",
    "ngx-cookie-service": "2.1.0",
    "ngx-quill": "4.5.0",
    "ngx-socket-io": "2.1.1",
    "perfect-scrollbar": "1.4.0",
    "prismjs": "1.15.0",
    "rxjs": "6.3.3",
    "rxjs-compat": "6.3.3",
    "tslib": "^1.9.3",
    "web-animations-js": "2.3.1",
    "zone.js": "0.8.28"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "0.13.8",
    "@angular/cli": "7.2.2",
    "@angular/compiler-cli": "7.2.13",
    "@angular/language-service": "7.2.1",
    "@angularclass/hmr": "2.1.3",
    "@types/googlemaps": "3.30.19",
    "@types/jasmine": "3.3.7",
    "@types/jasminewd2": "2.0.6",
    "@types/lodash": "4.14.120",
    "@types/node": "10.12.18",
    "codelyzer": "4.5.0",
    "jasmine-core": "3.3.0",
    "jasmine-spec-reporter": "4.2.1",
    "karma": "3.1.4",
    "karma-chrome-launcher": "2.2.0",
    "karma-coverage-istanbul-reporter": "2.0.4",
    "karma-jasmine": "2.0.1",
    "karma-jasmine-html-reporter": "1.4.0",
    "node-sass": "4.11.0",
    "protractor": "5.4.2",
    "quill": "1.3.6",
    "ts-node": "8.0.1",
    "tslint": "5.12.1",
    "typescript": "3.2.4",
    "webpack-bundle-analyzer": "3.0.3"
  }
}

Dockerfile

FROM node as builder

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY package*.json /usr/src/app/
RUN npm install


COPY . /usr/src/app

RUN npm run-script build

当它到达这个命令时:RUN npm install 编译一段时间后,它会抛出这个错误:

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@4.11.0 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the node-sass@4.11.0 postinstall 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/2019-05-24T06_30_43_945Z-debug.log

我需要做什么才能让它工作??

更多来自相同的错误..

In file included from ../../nan/nan.h:53:0,
                 from ../src/binding.cpp:1:
/root/.node-gyp/12.3.0/include/node/node.h:107:24: fatal error: util-inl.h: No such file or directory
 #  include <util-inl.h>
                        ^

据我了解,它应该通过 npm install 解决所有依赖项,但似乎不能。我确定文件 package.json 文件与我在 Dockerfile 中的工作目录位于同一目录中。

【问题讨论】:

  • 您可能需要更新 SASS 依赖项。
  • Angular 应用程序是否在主机上成功构建?
  • @leopal 你的意思是直接在 ubuntu 上?好吧,它在 package.json 的 npm install 命令上抛出错误,但它是针对其他依赖项的。 package.json 应该包含应用程序的所有依赖项,不是吗?
  • @qqilihq 我添加了一行作为 npm install node-sass@4.11.0 并且它抛出了同样的错误
  • @Sollosa 我的意思是直接在您的 docker 主机上,是的。如果它仍然在主机上抛出错误,那么这不是 docker 问题,而是 Angular 应用程序及其依赖项的问题。请更新您的 OP 以包含您的 package.json 以及 nodenpm 版本。

标签: angular docker npm


【解决方案1】:

您报告的问题可能与使用node 最新版本有关。我建议坚持使用最新的LTS 版本(稳定),目前是10.15.3

在我的主机 (windows10) 和 docker 容器上成功运行 npm i 和至少 package.json(显然包括您提供的依赖项的部分)。

这是我的Dockerfile

FROM node:10.15.3-alpine
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app   
#it seems git is required for the build process
RUN apk add git 
COPY package*.json /usr/src/app/
RUN npm i

如果您仍然遇到问题,那么角度应用程序有问题。

【讨论】:

  • 好吧,一切顺利,但现在我被困在最后一步:RUN npm run-script build... 它给出以下错误:npm ERR!缺少脚本:构建
  • 很高兴为您提供帮助。这是另一个问题,因此它应该作为一个新问题发布,包括所有必需的信息。
【解决方案2】:

如果您想使用 Node 11(据说是以上),则会出现以下问题:

Angular CLI: 7.0.3 Cannot find module 'node-sass'

我在 cmets 中建议更新 node-sass 依赖项(或将其添加为显式依赖项,如果尚未列出)。这为我解决了这个问题。

或者(并且可能更清洁),如果您将依赖项 @angular-devkit/build-angular(这是包含 node-sass 的依赖项)更新到当前版本,它应该会有所帮助——对我来说,使用 ^0.13.9 解决了节点 11 的问题.

无论如何,我建议:

  • 在您的 Docker 映像中使用 LTS 版本,如 leopal 所建议的那样
  • 明确将此版本固定在Dockerfile

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-16
    • 2020-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多