簡體   English   中英

構建 docker 圖像會引發 gyp ERR! 安裝npm時不行

[英]building docker image throws gyp ERR! not ok when installing npm

我已經構建了一個 vue.js 應用程序,並希望使用 docker 創建一個圖像。 但是,我得到了幾個 gyp ERR。 運行 docker 構建命令時的行。 使用 npm run serve 命令在我的機器上運行應用程序沒有問題。

#10 49.03 npm ERR! code 1
#10 49.03 npm ERR! path /app/node_modules/node-sass
#10 49.03 npm ERR! command failed
#10 49.03 npm ERR! command sh -c node scripts/build.js
#10 49.03 npm ERR! Building: /usr/local/bin/node /app/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
#10 49.03 npm ERR! gyp info it worked if it ends with ok
#10 49.03 npm ERR! gyp verb cli [
#10 49.03 npm ERR! gyp verb cli   '/usr/local/bin/node',
#10 49.03 npm ERR! gyp verb cli   '/app/node_modules/node-gyp/bin/node-gyp.js',
#10 49.03 npm ERR! gyp verb cli   'rebuild',
#10 49.03 npm ERR! gyp verb cli   '--verbose',
#10 49.03 npm ERR! gyp verb cli   '--libsass_ext=',
#10 49.03 npm ERR! gyp verb cli   '--libsass_cflags=',
#10 49.03 npm ERR! gyp verb cli   '--libsass_ldflags=',
#10 49.03 npm ERR! gyp verb cli   '--libsass_library='
#10 49.03 npm ERR! gyp verb cli ]
#10 49.03 npm ERR! gyp info using node-gyp@3.8.0
#10 49.03 npm ERR! gyp info using node@16.13.1 | linux | x64
#10 49.03 npm ERR! gyp verb command rebuild []
#10 49.03 npm ERR! gyp verb command clean []
#10 49.03 npm ERR! gyp verb clean removing "build" directory
#10 49.03 npm ERR! gyp verb command configure []
#10 49.03 npm ERR! gyp verb check python checking for Python executable "python2" in the PATH
#10 49.03 npm ERR! gyp verb `which` failed Error: not found: python2
#10 49.03 npm ERR! gyp verb `which` failed     at getNotFoundError (/app/node_modules/which/which.js:13:12)
#10 49.03 npm ERR! gyp verb `which` failed     at F (/app/node_modules/which/which.js:68:19)
#10 49.03 npm ERR! gyp verb `which` failed     at E (/app/node_modules/which/which.js:80:29)
#10 49.03 npm ERR! gyp verb `which` failed     at /app/node_modules/which/which.js:89:16
#10 49.03 npm ERR! gyp verb `which` failed     at /app/node_modules/isexe/index.js:42:5
#10 49.03 npm ERR! gyp verb `which` failed     at /app/node_modules/isexe/mode.js:8:5
#10 49.04 npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21)
#10 49.04 npm ERR! gyp verb `which` failed  python2 Error: not found: python2
#10 49.04 npm ERR! gyp verb `which` failed     at getNotFoundError (/app/node_modules/which/which.js:13:12)
#10 49.04 npm ERR! gyp verb `which` failed     at F (/app/node_modules/which/which.js:68:19)
#10 49.04 npm ERR! gyp verb `which` failed     at E (/app/node_modules/which/which.js:80:29)
#10 49.04 npm ERR! gyp verb `which` failed     at /app/node_modules/which/which.js:89:16
#10 49.04 npm ERR! gyp verb `which` failed     at /app/node_modules/isexe/index.js:42:5
#10 49.04 npm ERR! gyp verb `which` failed     at /app/node_modules/isexe/mode.js:8:5
#10 49.04 npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21) {
#10 49.04 npm ERR! gyp verb `which` failed   code: 'ENOENT'
#10 49.04 npm ERR! gyp verb `which` failed }
#10 49.04 npm ERR! gyp verb check python checking for Python executable "python" in the PATH
#10 49.04 npm ERR! gyp verb `which` failed Error: not found: python
#10 49.04 npm ERR! gyp verb `which` failed     at getNotFoundError (/app/node_modules/which/which.js:13:12)
#10 49.04 npm ERR! gyp verb `which` failed     at F (/app/node_modules/which/which.js:68:19)
#10 49.04 npm ERR! gyp verb `which` failed     at E (/app/node_modules/which/which.js:80:29)
#10 49.04 npm ERR! gyp verb `which` failed     at /app/node_modules/which/which.js:89:16
#10 49.04 npm ERR! gyp verb `which` failed     at /app/node_modules/isexe/index.js:42:5
#10 49.04 npm ERR! gyp verb `which` failed     at /app/node_modules/isexe/mode.js:8:5
#10 49.04 npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21)
#10 49.04 npm ERR! gyp verb `which` failed  python Error: not found: python
#10 49.04 npm ERR! gyp verb `which` failed     at getNotFoundError (/app/node_modules/which/which.js:13:12)
#10 49.04 npm ERR! gyp verb `which` failed     at F (/app/node_modules/which/which.js:68:19)
#10 49.04 npm ERR! gyp verb `which` failed     at E (/app/node_modules/which/which.js:80:29)
#10 49.04 npm ERR! gyp verb `which` failed     at /app/node_modules/which/which.js:89:16
#10 49.04 npm ERR! gyp verb `which` failed     at /app/node_modules/isexe/index.js:42:5
#10 49.04 npm ERR! gyp verb `which` failed     at /app/node_modules/isexe/mode.js:8:5
#10 49.04 npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21) {
#10 49.04 npm ERR! gyp verb `which` failed   code: 'ENOENT'
#10 49.04 npm ERR! gyp verb `which` failed }
#10 49.04 npm ERR! gyp ERR! configure error
#10 49.04 npm ERR! gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
#10 49.04 npm ERR! gyp ERR! stack     at PythonFinder.failNoPython (/app/node_modules/node-gyp/lib/configure.js:484:19)
#10 49.04 npm ERR! gyp ERR! stack     at PythonFinder.<anonymous> (/app/node_modules/node-gyp/lib/configure.js:406:16)
#10 49.04 npm ERR! gyp ERR! stack     at F (/app/node_modules/which/which.js:68:16)
#10 49.04 npm ERR! gyp ERR! stack     at E (/app/node_modules/which/which.js:80:29)
#10 49.04 npm ERR! gyp ERR! stack     at /app/node_modules/which/which.js:89:16
#10 49.04 npm ERR! gyp ERR! stack     at /app/node_modules/isexe/index.js:42:5
#10 49.04 npm ERR! gyp ERR! stack     at /app/node_modules/isexe/mode.js:8:5
#10 49.04 npm ERR! gyp ERR! stack     at FSReqCallback.oncomplete (node:fs:198:21)
#10 49.04 npm ERR! gyp ERR! System Linux 5.10.60.1-microsoft-standard-WSL2
#10 49.04 npm ERR! gyp ERR! command "/usr/local/bin/node" "/app/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
#10 49.04 npm ERR! gyp ERR! cwd /app/node_modules/node-sass
#10 49.04 npm ERR! gyp ERR! node -v v16.13.1
#10 49.04 npm ERR! gyp ERR! node-gyp -v v3.8.0
#10 49.04 npm ERR! gyp ERR! not ok
#10 49.04 npm ERR! Build failed with error code: 1
#10 49.27
#10 49.27 npm ERR! A complete log of this run can be found in:
#10 49.27 npm ERR!     /root/.npm/_logs/2021-12-26T11_47_39_634Z-debug.log
------

executor failed running [/bin/sh -c npm install]: exit code: 1

似乎 node-sass 是罪魁禍首,但我不明白如何在不刪除它的情況下解決這個問題,因為我的項目依賴於它。

Dockerfile:

# Choose the Image which has Node installed already
FROM node:lts-alpine

# install simple http server for serving static content
RUN npm install -g http-server

# make the 'app' folder the current working directory
WORKDIR /app

# copy both 'package.json' and 'package-lock.json' (if available)
COPY package*.json ./

# install project dependencies
RUN npm install

# copy project files and folders to the current working directory (i.e. 'app' folder)
COPY . .

# build app for production with minification
RUN npm run build

EXPOSE 8081
CMD [ "http-server", "dist" ]

package.json 文件:

{
  "name": "vue-argon-design-system",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "axios": "^0.24.0",
    "bootstrap-vue": "^2.0.4",
    "flatpickr": "^4.5.1",
    "nouislider": "^11.1.0",
    "register-service-worker": "^1.5.2",
    "sweetalert2": "^11.3.0",
    "vue": "^2.6.6",
    "vue-flatpickr-component": "^8.1.1",
    "vue-lazyload": "^1.2.6",
    "vue-multiselect": "^2.1.6",
    "vue-router": "^3.0.2",
    "vue2-datepicker": "^3.10.4",
    "vue2-transitions": "^0.2.3"

  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "^3.4.0",
    "@vue/cli-plugin-eslint": "^3.4.0",
    "@vue/cli-plugin-pwa": "^3.4.0",
    "@vue/cli-service": "^3.4.0",
    "node-sass": "^4.11.0",
    "sass-loader": "^7.1.0",
    "vue-template-compiler": "^2.6.6"
  }
}

正如 AAber 指出的那樣,問題是關於 python 而不是 node.js。 基本映像無法運行 python。 將圖像更新到 node:12.14-alpine 解決了它。 非常感謝。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM