Docker和npm-gyp错误!不好


10

一切都与我的客户工作,直到我试图解决一些网络断开的升级问题,react-scripts在我的docker客户服务,从3.0.13.3.0,使用npm install <package> --save和重新构建它。

但是随后它开始抱怨要求css-loaderstyle-loader,然后我安装了它们。然后它不起作用,我将设置恢复为3.0.1,同时使用--saveflag 卸载了先前的两个软件包,以便也将其删除node_modules/

现在,当我运行时docker-compose -f docker-compose-dev.yml build client尽管建立了客户端服务出现以下错误:

> fsevents@1.2.11 install /usr/src/app/node_modules/chokidar/node_modules/fsevents
> node-gyp rebuild

gyp info it worked if it ends with ok
gyp info using node-gyp@3.8.0
gyp info using node@11.12.0 | linux | x64
gyp ERR! configure error 
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
gyp ERR! stack     at PythonFinder.failNoPython (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:484:19)
gyp ERR! stack     at PythonFinder.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:406:16)
gyp ERR! stack     at F (/usr/local/lib/node_modules/npm/node_modules/which/which.js:68:16)
gyp ERR! stack     at E (/usr/local/lib/node_modules/npm/node_modules/which/which.js:80:29)
gyp ERR! stack     at /usr/local/lib/node_modules/npm/node_modules/which/which.js:89:16
gyp ERR! stack     at /usr/local/lib/node_modules/npm/node_modules/isexe/index.js:42:5
gyp ERR! stack     at /usr/local/lib/node_modules/npm/node_modules/isexe/mode.js:8:5
gyp ERR! stack     at FSReqCallback.oncomplete (fs.js:158:21)
gyp ERR! System Linux 4.9.184-linuxkit
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/src/app/node_modules/chokidar/node_modules/fsevents
gyp ERR! node -v v11.12.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 

> core-js@3.6.4 postinstall /usr/src/app/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
> https://opencollective.com/core-js 
> https://www.patreon.com/zloirock 

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> fsevents@1.2.11 install /usr/src/app/node_modules/jest-haste-map/node_modules/fsevents
> node-gyp rebuild

gyp info it worked if it ends with ok
gyp info using node-gyp@3.8.0
gyp info using node@11.12.0 | linux | x64
gyp ERR! configure error 
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
gyp ERR! stack     at PythonFinder.failNoPython (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:484:19)
gyp ERR! stack     at PythonFinder.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:406:16)
gyp ERR! stack     at F (/usr/local/lib/node_modules/npm/node_modules/which/which.js:68:16)
gyp ERR! stack     at E (/usr/local/lib/node_modules/npm/node_modules/which/which.js:80:29)
gyp ERR! stack     at /usr/local/lib/node_modules/npm/node_modules/which/which.js:89:16
gyp ERR! stack     at /usr/local/lib/node_modules/npm/node_modules/isexe/index.js:42:5
gyp ERR! stack     at /usr/local/lib/node_modules/npm/node_modules/isexe/mode.js:8:5
gyp ERR! stack     at FSReqCallback.oncomplete (fs.js:158:21)
gyp ERR! System Linux 4.9.184-linuxkit
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/src/app/node_modules/jest-haste-map/node_modules/fsevents
gyp ERR! node -v v11.12.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 

这是我的docker-compose-dev.yml

web:
    build:
      context: ./services/web
      dockerfile: Dockerfile-dev
    volumes:
      - './services/web:/usr/src/app'

    ports:
      - 5001:5000
    environment:
      - FLASK_ENV=development
      - APP_SETTINGS=brandio.config.DevelopmentConfig
      - DATABASE_URL=postgres://postgres:postgres@web-db:5432/web_dev 
      - DATABASE_TEST_URL=postgres://postgres:postgres@web-db:5432/web_test
      - SECRET_KEY=my_precious
    depends_on:  
      - web-db
      - redis

client:
    build:
      context: ./services/client
      dockerfile: Dockerfile-dev
    volumes:
      - './services/client:/usr/src/app'
      - '/usr/src/app/node_modules'
    ports:
      - 3000:3000
    environment:
      - NODE_ENV=development
      - REACT_APP_WEB_SERVICE_URL=${REACT_APP_WEB_SERVICE_URL}
    depends_on:
      - web

这是我的客户端 Dockerfile

# base image
FROM node:11.12.0-alpine

# set working directory
WORKDIR /usr/src/app

# add `/usr/src/app/node_modules/.bin` to $PATH
ENV PATH /usr/src/app/node_modules/.bin:$PATH

# install and cache app dependencies
COPY package.json /usr/src/app/package.json
COPY package-lock.json /usr/src/app/package-lock.json
RUN npm ci
RUN npm install react-scripts@3.3.0 -g --silent

# start app
CMD ["npm", "start"]

Web服务Dockerfile,客户端依赖。我试图在环境中安装node-gyp,并且python肯定在这里。无济于事:

FROM python:3.7-slim-buster

RUN apt-get update && apt-get -y dist-upgrade 
RUN apt-get -y install node-gyp build-essential libssl-dev libffi-dev libblas3 libc6 liblapack3 gcc python3-dev 
RUN apt install -y netcat

# set working directory
WORKDIR /usr/src/app

COPY ./requirements.txt /usr/src/app/requirements.txt 
RUN pip3 install -r requirements.txt

# add entrypoint.sh
COPY ./entrypoint.sh /usr/src/app/entrypoint.sh

RUN chmod +x /usr/src/app/entrypoint.sh

# add app
COPY . /usr/src/app

# run server
CMD ["/usr/src/app/entrypoint.sh"]

Package.json

    {
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "axios": "^0.18.1",
    "react": "^16.8.6",
    "react-alert": "^5.5.0",
    "react-dom": "^16.8.6",
    "react-hot-loader": "^4.5.3",
    "react-html-parser": "^2.0.2",
    "react-player": "^1.13.0",
    "react-router-dom": "^5.0.0",
    "react-scripts": "^3.3.0",
    "react-transition-group": "^2.9.0",
    "spotify-web-api-js": "^1.2.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "enzyme": "^3.11.0",
    "enzyme-adapter-react-16": "^1.15.2"
  }
}

现在回到3.3.0,但问题仍然存在。


$ npm list 向我展示了对等依赖项的问题:

npm ERR! peer dep missing: @types/react@^15.0.0 || ^16.0.0, required by react-hot-loader@4.12.18
npm ERR! peer dep missing: typescript@^3.2.1, required by react-scripts@3.3.0
npm ERR! peer dep missing: node-sass@^4.0.0, required by sass-loader@8.0.0
npm ERR! peer dep missing: sass@^1.3.0, required by sass-loader@8.0.0
npm ERR! peer dep missing: fibers@>= 3.1.0, required by sass-loader@8.0.0
npm ERR! peer dep missing: typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta, required by tsutils@3.17.1
npm ERR! peer dep missing: typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta, required by tsutils@3.17.1

我不知道问题是否相关。


我也已经node-gyp全局安装,经过测试,错误仍然存​​在,然后再次卸载。


我该如何解决?


似乎容器node:11.12.0-alpine未安装python发行版
Jens

1
我不明白 使用这种精确的设置已经工作了几个月。
8位博尔赫斯

也许可以,但是我在安装Python的dockerfile中看不到任何东西,所以如果以前可以工作,那真是个奇迹。我使用的解决方案有两个dockerfile,一个用于节点,一个用于python,并带有docker-compose.yml,可同时加载这两个文件。
Mike'Pomax'Kamermans

python安装在web服务中,客户端依赖。这有意义吗?
8-Bit Borges

它并非没有:至少没有没有关于您在何处定义该web任务及其内容的附加信息。
Mike'Pomax'Kamermans

Answers:


3

将以下行添加到客户端Dockerfile中:

RUN apk update && apk add python make g++

所以它应该看起来像这样:

# base image
FROM node:11.12.0-alpine

RUN apk update && apk add python make g++

# set working directory
WORKDIR /usr/src/app

# add `/usr/src/app/node_modules/.bin` to $PATH
ENV PATH /usr/src/app/node_modules/.bin:$PATH

# install and cache app dependencies
COPY package.json /usr/src/app/package.json
COPY package-lock.json /usr/src/app/package-lock.json
RUN npm ci
RUN npm install react-scripts@3.3.0 -g --silent

# start app
CMD ["npm", "start"]

我的网页图片是python3.7。不应该在python3这里添加吗?
8位博尔赫斯

1
建议的更改是针对客户端docker文件而不是Web docker文件。需要python来重建node-gyp模块。此python与您的Web泊坞窗中的python无关。
AAber

我发现有趣的是,为了能够npm ci在ci / cd中工作,您需要使用python作为依赖项。
teseo
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.