Strange Git Error on Docker NPM Install - node.js

I had a working Dockerfile until literally a day ago when it just seemed to break. I didn't make any changes to my dependencies - but I am getting the following error:
[91mnpm ERR! code ENOGIT
[0m
[91mnpm ERR! No git binary found in $PATH
npm ERR!
npm[0m
[91m ERR! Failed using git.
npm ERR! Please check if you have git installed and in your PATH.
[0m
[91m
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2017-09-28T21_12_50_050Z-debug.log
[0m
Removing intermediate container be9d5bfe5521
The command '/bin/sh -c npm install' returned a non-zero code: 1
This is super strange because this wasn't happening before. I'm also attaching my Dockerfile. The things I've tried so far are adding git (third line), and also trying to export the path. Nothing seems to be working.
FROM ubuntu:latest
RUN apt-get update
RUN apt-get install -y git
FROM node:alpine
RUN npm install sails -g
#RUN npm install git -g
#RUN export PATH="$HOME/usr/bin/git:$PATH"
RUN mkdir -p /service/app
WORKDIR /service/app
COPY package.json /service/app
RUN npm install
COPY . /service/app
EXPOSE 80
CMD NODE_ENV=production sails lift

One reason for this could be that you are using the slim version of node in your Dockerfile:
FROM node:8-slim
I presume this does not include git, because when I changed to the full version the error went away:
FROM node:8.11.2

Try the following:
RUN apk update && \
apk add --update git && \
apk add --update openssh
The git binary within the docker container becomes available at /usr/bin/git

I had the same issue. It was due to lack of git. Below is how it worked
FROM node:alpine
RUN apk add git
RUN npm install ...

Related

How to set up Truffle and Ganache with Docker on Apple Silicon

error - node-gyp-build: Permission denied while setting up truffle and ganache with docker on Apple Silicon
npm ERR! code 127
npm ERR! path /root/.nvm/versions/node/v17.9.0/lib/node_modules/truffle/node_modules/leveldown
npm ERR! command failed
npm ERR! command sh -c node-gyp-build
npm ERR! sh: 1: node-gyp-build: Permission denied
These are some steps i followed to install truffle with docker on my m1 Macbook.
I'll be doing it for ubuntu image container
docker run -it ubuntu
on your container execute below:
apt-get update && apt-get upgrade
apt-get install sudo build-essential python3 wget curl
Then install nvm from https://github.com/nvm-sh/nvm#install--update-script
On above link there must be these two commands but with updated versions
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
then install node and npm with:
nvm install node
node install npm
npm install npm
after executing
nvm install-latest-npm
you'll find a statement to update npm to the latest version, execute that command, which should look like, npm install -g npm#8.6.0, after that install truffle
npm install -g truffle
there will be a permission issue in executing above command for which you've to execute
sudo chown -R $(whoami) <path to node_modules directory>
Note: the above command has path to node_modules you need to find the path to your node_modules from your error. in my case it was /root/.nvm/versions/node/v17.9.0/lib/node_modules/ so i executed, sudo chown -R $(whoami) /root/.nvm/versions/node/v17.9.0/lib/node_modules/
retry npm install -g truffle
after this you should be done with installation, but you would face problems where you couldn't execute the truffle file.
for this just allow your truffle file to be executed by running:
chmod u+x <path to truffle> you may find the path to truffle with which truffle, execute as below.
chmod u+x /root/.nvm/versions/node/v17.9.0/bin/truffle
For Ganache installation:
npm install ganache --global
To your package.json add,
"scripts": {
"ganache": "ganache --wallet.seed myCustomSeed"
}
Then execute,
npm run ganache
you should be able to see output something like RPC Listening on 127.0.0.1:8545
now execute truffle console, make sure you add correct port number like above 8545 in file truffle-config.js of your code, when you use it.
now execute truffle console

npm WARN old lockfile The package-lock.json file was created with an old version of npm

I've a dockerfile as below, but during RUN npm ci step, there is a warning,
npm WARN old lockfile The package-lock.json file was created with an old version of npm
which I can not able to figure out..
I tried with npm install rather npm ci and added the --package-lock flag, but I am still getting this warning. It’s a kind of warning that I have to ignore it or what should I do to solve this?
Step 12/26 : RUN npm ci --production --package-lock && npm ci --production --package-lock --prefix ./ui-runner
---> Running in 3473c209b98c
npm WARN old lockfile
npm WARN old lockfile The package-lock.json file was created with an old version of npm,
npm WARN old lockfile so supplemental metadata must be fetched from the registry.
npm WARN old lockfile
npm WARN old lockfile This is a one-time fix-up, please be patient...
npm WARN old lockfile
Here is my Dockerfile.
FROM node:14.17.1-alpine3.13 AS builder
WORKDIR /usr/src/app
COPY package.json package-lock.json* ./
COPY ui-runner/package*.json ./ui-runner/
COPY .npmrc .npmrc
COPY ui-runner/.npmrc ./ui-runner/.npmrc
RUN npm -g install npm#7.19.1
RUN npm ci --production --package-lock && \
npm ci --production --package-lock --prefix ./ui-runner
RUN rm -f .npmrc && \
rm -f ui-runner/.npmrc
FROM node:14.17.1-alpine3.13
WORKDIR /usr/src/app
RUN apk update && apk add --no-cache curl bash
RUN addgroup -g 1001 test && \
adduser -S -u 1001 -G test test
RUN chown -R test /usr/src/app && \
chmod 755 /usr/src/app
COPY --from=builder /usr/src/app /usr/src/app
COPY . .
RUN npm run build:docker
USER test
EXPOSE 3000 9183
CMD [ "npm", "run", "start:ui-runner" ]
There are several ways to deal with this:
Ignore it. It's just a warning and does not affect the installation of modules.
Run npm install --package-lock-only (with the newer version of npm) to regenerate a package-lock.json. Commit the updated version of package-lock.json to the repo/Docker image or whatever.
Downgrade npm to an older version in production. Consider running npm version 6 as that is what ships with the current (as of this writing) Long Term Support (LTS) version of Node.js. In the case being asked about in this question, I imagine you can just leave out the RUN npm -g install npm#7.19.1 from the Dockerfile and instead use the version of npm that is installed with the Docker image (which in this case will almost certainly be npm#6 since that is what ships with Node.js 14.x).
If you already have a version of npm installed but want to run one command with an older version of npm but otherwise keep the newer version, you can use npx (which ships with npm) to do that. For example, npx npm#6 ci would run npm ci with npm version 6 even if you have version 7 installed.
I had a similar problem but upgrading npm npm i -g npm on my machine before building the image solved it for me. You may still get the warn message but the image build process won't be halted.
An easy solution to this is to use NVM to manage your node versions. Especially on Linux this saves a lot of trouble with file permissions, developing in different environments, etc. NPM recommends this in their documentation here.
This error for me was solved by switching Node.js versions with nvm,
nvm install 14
nvm use 14
It is always an easy thing to try and switch to a slightly older or newer Node.js version if you are running into weird Node.js or npm issues.
I am having the same problem as well after upgrading my npm version. It seems like a bug from npm 7.19.1, and I'd suggest to downgrade to an older version.
You can check below for all the npm versions
https://www.npmjs.com/package/npm?activeTab=versions
Install the desired version with this command in the console, and substitute "V" with your desired version:
npm install -g npm#"V"
TL;DR
As Trott suggested it is totally fine to ignore the warning. To fix the warning/problem keep reading.
The problem/warning is with the line:
RUN npm -g install npm#7.19.1
Removing this line should fix the problem/warning.
Explanation
The package-lock generated which is part of your source repository ideally is generated with npm version < npm#7 which ships with Node.js <= node#14.x.x. My guess comes from your first line of Dockerfile.
FROM node:14.17.1-alpine3.13 AS builder
For example Node.js LTS v14.17.1 ships with npm#6.14.13. See the full release list here.
npm#5, npm#6 generate package-lock#v1, which is now a legacy release as per this link. And npm#7 which is the latest release generates package-lock#v2. When you do: npm -g install npm#7.19.1. It overrides your existing package-lock#v1 with package-lock#v2 giving out the warning in the process.`
npm WARN old lockfile The package-lock.json file was created with an old version of npm`
The updated Dockerfile should look like this:
FROM node:14.17.1-alpine3.13 AS builder
WORKDIR /usr/src/app
COPY package.json package-lock.json* ./
COPY ui-runner/package*.json ./ui-runner/
COPY .npmrc .npmrc
COPY ui-runner/.npmrc ./ui-runner/.npmrc
RUN npm ci --production --package-lock && \
npm ci --production --package-lock --prefix ./ui-runner
RUN rm -f .npmrc && \
rm -f ui-runner/.npmrc
FROM node:14.17.1-alpine3.13
WORKDIR /usr/src/app
RUN apk update && apk add --no-cache curl bash
RUN addgroup -g 1001 test && \
adduser -S -u 1001 -G test test
RUN chown -R test /usr/src/app && \
chmod 755 /usr/src/app
COPY --from=builder /usr/src/app /usr/src/app
COPY . .
RUN npm run build:docker
USER test
EXPOSE 3000 9183
CMD [ "npm", "run", "start:ui-runner" ]
I was facing a similar issue. After reading the previous comments, I noticed that the Node.js version installed on my machine was v14.17.5 and the npm version was v7.19.1. Referring to version history lookup and downgrading npm to v6.14.14 (compatible against node v14.17.5) resolved issue.
First check for your Node.js version: Go to a cmd prompt and
node -v
Based on the version, check the node-sass version and install it:
npm node-sass#version
From node-sass:
Node 16 - 6.0+
Node 15 - 5.0+
Node 14 - 4.14+
Node 13 - 4.13+,
Node 12 - 4.12+
Node 11 - 4.10+,
Node 10 - 4.9+,
Node 8 - 4.5.3+,
Node <8 - <5.0
I had similar problem with Strapi v4
I used:
1)
nvm use 16.15.1
(old was 14.X.X)
2)
npm rebuild
npm install
Seem to work now.

Docker Node Sass does not yet support your current environment

FROM node:latest as nodeBuilder
RUN npm rebuild node-sass
WORKDIR /var/www/app
COPY ./webapp /var/www/app
RUN npm install
RUN npm run build
RUN rm -rf node_module
when i run this got this error
Error: Node Sass does not yet support your current environment: Linux 64-bit with Unsupported runtime (88)
For more information on which environments are supported please see:
https://github.com/sass/node-sass/releases/tag/v4.14.1
i use
FROM node:12.22.1 as nodeBuilder
WORKDIR /var/www/app
COPY ./backend /var/www/app
RUN rm -rf node_module
RUN npm install
RUN npm rebuild node-sass
RUN npm run build
RUN rm -rf node_module
and it's work because of node v15 dose not support node_sass

BCRYPT - Build from source on Alpine:node and causes segfaults using this docker file when its used

Build this docker file and try and use Bcrypt to complete a hash and it will segfault, and I can't figure out why for the life of me.
FROM mhart/alpine-node:9.1.0
MAINTAINER James Claridge <james#claridgeand.co>
RUN mkdir /app
WORKDIR /app
RUN apk --no-cache add --virtual builds-deps build-base python
RUN npm config set python /usr/bin/python
RUN npm i -g npm
RUN npm install
RUN npm rebuild bcrypt --build-from-source
RUN apk del builds-deps
Use bcryptjs, it doesn't require you to install additional dependencies and rebuild from source. See https://www.npmjs.com/package/bcryptjs
If you really want to use the bcrypt, see their issue on github and their instructions. There are some workaround there, but this will require some additional dependency installing. The easiest way to keep using bcrypt would be to not use the alpine version, but the ubuntu version of node (with its additional overhead).
The problem is that you're trying to install a npm version that has a bug.
In your installation, RUN npm install doesn't work, so, rebuild bcrypt crashes.
After that, you should add before npm install some commands like explained in these links:
error-cannot-find-module-npmlog-after-npm-update-g
Issue npm version 5.4.1 solved upgrading to 6.1.0
EDIT: It's an issue related to alpine-node version available packages:
Use this Dockerfile:
FROM mhart/alpine-node:latest
MAINTAINER James Claridge <james#claridgeand.co>
RUN apk update
RUN mkdir /app
WORKDIR /app
RUN apk --no-cache add --virtual builds-deps build-base python
RUN npm config set python /usr/bin/python
RUN npm i -g npm
RUN npm install
RUN npm rebuild bcrypt --build-from-source
RUN apk del builds-deps

Bitbucket Pipeline npm install fails with "npm ERR! fatal: unable to access"

I'm trying to run test cases in my node app using Bitbucket pipeline as follows.
image: channagayan/node_test:latest
pipelines:
default:
- step:
caches:
- node
script: # Modify the commands below to build your repository.
- cd NodeApi && pwd && npm install
- npm test
But it fails giving following error
+ cd NodeApi && pwd && npm install
/opt/atlassian/pipelines/agent/build/NodeApi
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t https://git#github.com/peterbraden/node-opencv.git
npm ERR!
npm ERR! fatal: unable to access 'https://git#github.com/peterbraden/node-opencv.git/': Problem with the SSL CA cert (path? access rights?)
npm ERR!
npm ERR! exited with error code: 128
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-05-01T09_15_55_789Z-debug.log
My Dockerfile is as follows,
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get install -y --no-install-recommends \
build-essential \
cmake \
python-software-properties \
pkg-config \
wget \
&& rm -rf /var/lib/apt/lists/*
#node installation goes here....
RUN apt-get update && apt-get install -y git
#opencv installation goes here....
ENV LD_LIBRARY_PATH /usr/local/lib
WORKDIR /usr/src/app
EXPOSE 3001
It seems like Bitbucket is not accessing the internet from the docker container. Appreciate any help to resolve this.

Resources