简体   繁体   中英

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

I've built a vue.js application and wanted to create an image using docker. However, I get several gyp ERR. lines when I run the docker build command. I have no problem running the app on my machine using the npm run serve command.

#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

It seems that node-sass is the culprit but I can't understand how I can solve this issue without removing it as my project depends on it.

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 file:

{
  "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"
  }
}

As AAber has pointed out the problem was about python and not node.js. The base image could not run python. Updating the image to node:12.14-alpine solved it. Many thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM