Home > Mobile >  Dockerizing the an application, throws 'npm WARN tar ENOENT: no such file or directory' wh
Dockerizing the an application, throws 'npm WARN tar ENOENT: no such file or directory' wh

Time:10-11

I created a docker file for my application. This is my Dockerfile

FROM node:14.20.1-alpine3.15
RUN addgroup app && adduser -S -G app app
USER app
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]

When trying to build an image using docker build -t app . It is failing at npm install instruction, with the following error

#9 30.84 npm WARN tar ENOENT: no such file or directory, open '/app/node_modules/.staging/@amcharts/amcharts4-geodata-e29272c3/estoniaLow.d.ts'
#9 30.86 npm WARN tar ENOENT: no such file or directory, open '/app/node_modules/.staging/tslint-78b3aa2e/lib/rules/completed-docs/exclusion.d.ts'
#9 30.86 npm WARN tar ENOENT: no such file or directory, open '/app/node_modules/.staging/rxjs-c65985b6/_esm2015/internal/OuterSubscriber.js'
#9 30.87 npm WARN tar ENOENT: no such file or directory, open '/app/node_modules/.staging/rxjs-31d24ad4/operators/onErrorResumeNext.js'
#9 30.87 npm WARN tar ENOENT: no such file or directory, open '/app/node_modules/.staging/@angular/compiler-cli-923906dd/ngcc/src/ngcc_options.js'

I even tried to clear the cache and made sure the user had enough privileges.

CodePudding user response:

I faced the same issue. Just to debug, I tried copying the package.json file only instead of package*.json, rebuild the image then the following error popped up.

#9 78.90 npm ERR! code ENOENT
#9 78.90 npm ERR! syscall spawn git
#9 78.90 npm ERR! path git
#9 78.91 npm ERR! errno -2
#9 78.93 npm ERR! enoent Error while executing:
#9 78.93 npm ERR! enoent undefined ls-remote -h -t ssh://[email protected]/zingchart/zingchart-constants.git
#9 78.93 npm ERR! enoent
#9 78.94 npm ERR! enoent
#9 78.94 npm ERR! enoent spawn git ENOENT
#9 78.94 npm ERR! enoent This is related to npm not being able to find a file.
#9 78.94 npm ERR! enoent 

As git, bash are not part of alpine. So installing git & bash would solve the problem. So add the below command before npm install instruction

RUN apk update && apk upgrade && apk add --no-cache bash git openssh

or simply use apk add --no-cache bash git openssh

If you are using some user to install, have appropriate permission (like root) else it throws unable to lock the package database.

Dockerfile would look this

FROM node:14.20.1-alpine3.15
RUN apk add --no-cache bash git openssh
RUN addgroup app && adduser -S -G app app
USER app
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
  • Related