【问题标题】:Unable to install packages correctly in docker无法在 docker 中正确安装软件包
【发布时间】:2021-12-15 23:15:10
【问题描述】:

我可以使用 npm 安装所有软件包,但两天前我收到了这个错误。

Step 8/12 : RUN npm install
 ---> Running in aedc04c5281e

> sharp@0.25.4 install /home/project/website/node_modules/sharp
> (node install/libvips && node install/dll-copy && prebuild-install --runtime=napi) || (node-gyp rebuild && node install/dll-copy)

info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.9.1/libvips-8.9.1-linuxmusl-x64.tar.gz

> cwebp-bin@5.1.0 postinstall /home/project/website/node_modules/cwebp-bin
> node lib/install.js

  ⚠ spawn /home/project/website/node_modules/cwebp-bin/vendor/cwebp ENOENT
  ⚠ cwebp pre-build test failed
  ℹ compiling from source
...

这是我的 docker 文件

FROM node:12-alpine

RUN apk add --no-cache build-base gcc autoconf automake libtool zlib-dev libpng-dev nasm

RUN mkdir -p /home/project/website/node_modules && chown -R node:node /home/project/website

WORKDIR /home/project/website

COPY /package*.json ./

USER node

RUN npm cache verify

RUN npm install

COPY --chown=node:node . .

RUN chmod +x wait-for.sh

RUN chmod -R 0755 /home/project/website/src/views/

EXPOSE 8080

建筑完成后,我在日志中得到了这个

internal/modules/cjs/loader.js:968
  throw err;
  ^

Error: Cannot find module '/home/project/website/node_modules/.bin/nodemon'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
    at Function.Module._load (internal/modules/cjs/loader.js:841:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

在我运行以下 cmd 之后 docker-compose run website sh -c "npm list --depth=0" 我明白了

+-- UNMET DEPENDENCY bcryptjs@2.4.3
+-- UNMET DEPENDENCY compression@1.7.4
| +-- accepts@1.3.7
| +-- bytes@3.0.0
| +-- compressible@2.0.18
| +-- debug@2.6.9
| +-- on-headers@1.0.2
| +-- safe-buffer@5.1.2
| `-- vary@1.1.2
+-- UNMET DEPENDENCY cors@2.8.5
| +-- object-assign@4.1.1
| `-- vary@1.1.2
+-- UNMET DEPENDENCY dateformat@3.0.3
+-- UNMET DEPENDENCY dotenv@8.2.0
+-- UNMET DEPENDENCY ejs@3.1.5
| `-- jake@10.8.2
+-- UNMET DEPENDENCY express@4.17.1
...

我的包裹是

{
  "name": "website",
  "version": "0.0.0",
  "main": "app.js",
  "scripts": {
    "start": "nodemon src/app.js"
  },
  "author": "Noah Lc",
  "license": "ISC",
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "compression": "^1.7.4",
    "cors": "^2.8.5",
    "dateformat": "^3.0.3",
    "dotenv": "^8.2.0",
    "ejs": "^3.1.3",
    "express": "^4.17.1",
    "fs": "0.0.1-security",
    "helmet": "^4.1.1",
    "image-size": "^0.8.3",
    "imagemin": "^7.0.1",
    "imagemin-mozjpeg": "^9.0.0",
    "imagemin-webp": "^6.0.0",
    "jsonwebtoken": "^8.5.1",
    "mongoose": "^5.7.7",
    "multer": "^1.4.2",
    "nodemailer": "^6.4.11",
    "nodemon": "^2.0.3",
    "sharp": "^0.25.4",
    "sitemap": "^6.2.0",
    "slugify": "^1.4.0",
    "superagent": "^5.2.2",
    "validator": "^12.0.0",
    "winston": "^3.3.3"
  },
  "devDependencies": {}
}

是否有任何干净的方法可以跳过插件本身中这些下降的构建前和构建后步骤,以避免容器化环境中的任何问题?

【问题讨论】:

  • 我在您包含的日志中没有看到任何错误,只是一个模块正在编译,因为没有预构建二进制文件
  • 嗨,我已经更新了我的问题。你可以再看看。
  • 可以包含你的 package.json 文件吗?
  • 我已经完成了@Seblor

标签: node.js docker npm


【解决方案1】:
RUN apk add --no-cache \
--update \
build-base \
mesa-dev \
gcc \
autoconf \
automake \
libtool \
zlib-dev \
nasm \
mesa \
libxi \
libpng-dev \
libjpeg \
jpeg-dev

【讨论】:

  • 它对我有用,但也许还有一些额外的东西。
  • 请不要只发布代码作为答案,还要解释您的代码的作用以及它如何解决问题的问题。带有解释的答案通常更有帮助,质量更高,更有可能吸引投票。
  • 感谢您的澄清,我只是第一次回答stackoverflow。以后,我会避免这个错误。
  • 为什么不现在避免它并改进这个答案呢?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-01
  • 2022-01-01
  • 2018-06-25
  • 2015-09-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多