node.jswindowsdockernode-pre-gyp

How to solve docker related issue with /bin/sh: node-pre-gyp: not found?


A day ago I began to learn about Docker on my own. So I downloaded the app to my Windows 10 desktop and began the tutorial they recommended through the app. At one point they ask me to create a docker file with the following content:

FROM node:12-alpine WORKDIR /app COPY . . RUN yarn install --production CMD ["node", "/app/src/index.js"]

which I did to path: D:\docker_stuff\app under name "Dockerfile" with no extension. Next they ask me to run this command "docker build -t getting-started ." and here is where I am having issues as the command throws errors like:

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

What I tried:

  1. Installed node

D:\docker_stuff\app>node -v v12.16.3;

  1. Installed npm

D:\docker_stuff\app>npm -v 6.14.4;

  1. Ran command independently: node-pre-gyp install --fallback-to-build which throws a lot more issues:

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

  1. Modified the package.json file from the git project where I added line <"bcrypt": "^3.0.6",> under "dependencies": { ;

  2. Python is installed.

I feel that there might be an issue with the package.json file rather than my desktop, but I don't know for sure and if that is the issue how can I fix it? I know I'm a noob but could anyone provide me with some guidance?


Solution

  • "bcrypt": "^3.0.6" requires python to be installed and the image you used in your Dockerfile node:12-alpine is a very minimal image for nodejs.

    Either you use an ubuntu image and install python to the container you are building or you can use bcryptjs instead.

    You can add <"bcryptjs": "^2.4.3",> or just run npm i bcryptjs.

    It says on the README.md of bcyptjs that it will be 30% slower than bcrypt but you won't have to worry about python dependecy on your app.