gpt4 book ai didi

node.js - 如何解决/bin/sh : node-pre-gyp: not found? 与 docker 相关的问题

转载 作者:行者123 更新时间:2023-12-02 18:59:48 24 4
gpt4 key购买 nike

一天前,我开始自学Docker。所以我将应用下载到我的 Windows 10 桌面,并开始学习他们通过应用推荐的教程。有一次,他们要求我创建一个包含以下内容的 docker 文件:
FROM node:12-alpine
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["node", "/app/src/index.js"]

我对路径所做的:D:\docker_stuff\app在名称“Dockerfile”下,没有扩展名。接下来他们要求我运行这个命令“docker build -t getting-started”。这是我遇到问题的地方,因为该命令会引发以下错误:
D:\docker_stuff\app>docker build -t getting-started .
Sending build context to Docker daemon 4.673MB
Step 1/5 : FROM node:12-alpine
---> 7a48db49edbf
Step 2/5 : WORKDIR D:\docker_stuff\app
---> Using cache
---> 44ba6501de00
Step 3/5 : COPY . .
---> 44164775d408
Step 4/5 : RUN yarn install --production
---> Running in 5df554d6bac8
yarn install v1.22.4
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.9: The platform "linux" is incompatible with this module.
info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
error /D:docker_stuffapp/node_modules/bcrypt: Command failed.
Exit code: 127
Command: node-pre-gyp install --fallback-to-build
Arguments:
Directory: /D:docker_stuffapp/node_modules/bcrypt
Output:
/bin/sh: node-pre-gyp: not found

我尝试了什么:

  • 已安装 Node
  • D:\docker_stuff\app>node -v
    v12.16.3;
  • 安装 npm
  • D:\docker_stuff\app>npm -v
    6.14.4;
  • 独立运行命令:node-pre-gyp install --fallback-to-build 引发更多问题:
  • D:\docker_stuff\app>node-pre-gyp install --fallback-to-build
    node-pre-gyp info it worked if it ends with ok
    node-pre-gyp info using node-pre-gyp@0.14.0
    node-pre-gyp info using node@12.16.3 | win32 | x64
    node-pre-gyp WARN Using needle for node-pre-gyp https download
    node-pre-gyp ERR! install error
    node-pre-gyp ERR! stack Error: 101-app package.json is not node-pre-gyp ready:
    node-pre-gyp ERR! stack package.json must declare these properties:
    node-pre-gyp ERR! stack binary.module_name
    node-pre-gyp ERR! stack binary.module_path
    node-pre-gyp ERR! stack binary.host
    node-pre-gyp ERR! stack at validate_config (C:\Users\KahnTrevor\AppData\Roaming\npm\node_modules\node-pre-gyp\lib\util\versioning.js:220:15)
    node-pre-gyp ERR! stack at Object.module.exports.evaluate (C:\Users\KahnTrevor\AppData\Roaming\npm\node_modules\node-pre-gyp\lib\util\versioning.js:279:5)
    node-pre-gyp ERR! stack at install (C:\Users\KahnTrevor\AppData\Roaming\npm\node_modules\node-pre-gyp\lib\install.js:241:31)
    node-pre-gyp ERR! stack at Object.self.commands.<computed> [as install] (C:\Users\KahnTrevor\AppData\Roaming\npm\node_modules\node-pre-gyp\lib\node-pre-gyp.js:52:37)
    node-pre-gyp ERR! stack at run (C:\Users\KahnTrevor\AppData\Roaming\npm\node_modules\node-pre-gyp\bin\node-pre-gyp:82:30)
    node-pre-gyp ERR! stack at Object.<anonymous> (C:\Users\KahnTrevor\AppData\Roaming\npm\node_modules\node-pre-gyp\bin\node-pre-gyp:134:1)
    node-pre-gyp ERR! stack at Module._compile (internal/modules/cjs/loader.js:1133:30)
    node-pre-gyp ERR! stack at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
    node-pre-gyp ERR! stack at Module.load (internal/modules/cjs/loader.js:977:32)
    node-pre-gyp ERR! stack at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    node-pre-gyp ERR! System Windows_NT 10.0.18363
    node-pre-gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\KahnTrevor\\AppData\\Roaming\\npm\\node_modules\\node-pre-gyp\\bin\\node-pre-gyp" "install" "--fallback-to-build"
    node-pre-gyp ERR! cwd D:\docker_stuff\app
    node-pre-gyp ERR! node -v v12.16.3
    node-pre-gyp ERR! node-pre-gyp -v v0.14.0
    node-pre-gyp ERR! not ok
    101-app package.json is not node-pre-gyp ready:
    package.json must declare these properties:
    binary.module_name
    binary.module_path
    binary.host
  • 修改了 git 项目中的 package.json 文件,我在 "dependencies"下添加了行 <"bcrypt": "^3.0.6",>: { ;
  • Python 已安装。

  • 我觉得 package.json 文件而不是我的桌面可能存在问题,但我不确定,如果这是问题,我该如何解决?我知道我是菜鸟,但谁能给我一些指导?

    最佳答案

    "bcrypt": "^3.0.6"需要安装 python 和您在 Dockerfile 中使用的镜像 node:12-alpine是 nodejs 的一个非常小的图像。

    您可以使用 ubuntu 镜像并将 python 安装到您正在构建的容器中,也可以使用 bcryptjs反而。

    你可以添加 <"bcryptjs": "^2.4.3",> 或者直接运行 npm i bcryptjs .

    它在 README.md 上说的 bcyptjs它将比 bcrypt 慢 30%但您不必担心您的应用程序对 python 的依赖。

    关于node.js - 如何解决/bin/sh : node-pre-gyp: not found? 与 docker 相关的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61747484/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com