5

my npm -g works perfectly but i really dont know why my local npm doesn't work

npm ERR! code EACCES
npm ERR! syscall open
npm ERR! path /home/user/express/todoapp-api/package-lock.json
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, open '/home/user/express/todoapp-api/package-lock.json'
npm ERR!  [Error: EACCES: permission denied, open '/home/user/express/todoapp-api/package-lock.json'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'open',
npm ERR!   path: '/home/user/express/todoapp-api/package-lock.json'
npm ERR! }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/user/.npm/_logs/2022-04-16T09_47_36_160Z-debug-0.log

permissions

drwxrwxr-x  7 user user  4096 Apr 16 11:44 .
drwxrwxr-x  5 user user  4096 Apr 16 11:30 ..
-rw-rw-r--  1 user user   417 Apr 16 12:20 app.js
drwxr-xr-x  2 user user  4096 Apr 16 11:15 bin
drwxrwxr-x  2 user user  4096 Apr 16 11:46 config
drwxrwxr-x  2 user user  4096 Apr 16 11:24 models
drwxr-xr-x 64 user user  4096 Apr 16 12:41 node_modules
-rw-rw-r--  1 user user   271 Apr 16 12:21 package.json

-rw-r--r--  1 root root 38736 Apr 16 12:21 package-lock.json
drwxr-xr-x  2 user user  4096 Apr 16 11:27 routes

is it a must that package-lock.json require root previledges??

3
  • see: Resolving lockfile conflicts
    – Luuk
    Commented Apr 16, 2022 at 10:03
  • I consider this to be a bug in NPM. If package-lock.json is read only then npm install should still work because the lock file should be read and not written during that operation.
    – mjaggard
    Commented Jun 7, 2022 at 11:30
  • The package-lock file should be the same user as the rest of the project, not root. The fact that it is root indicates that you have accidentally done sudo npm install at some point before this.
    – slebetman
    Commented Mar 10 at 22:36

3 Answers 3

1

Check your local path and the path you are executing the command. I faced this issue due to manual error. I was trying to run npm command from different path than the path in which package related files are present.

0

Please refer to this post for more details

This error is occurring because of permission error. Lets give node user permission with our app folder.

FROM node:18.6.0-alpine3.15
RUN addgroup app && adduser -S -G app app
USER app
WORKDIR /app
COPY --chown=app:node package*.json .
RUN npm install
COPY --chown=app:node . .
ENV API_URL=http://api.myapp.com/
EXPOSE 3000
# Shell form
# /bin/sh
# This command will spin a new shell and execute the command there
# CMD npm start

# Exec form
CMD ["npm", "start"]

Build the image and then run the application

docker run -d -p 4000:3000 --name yellow-lime react-app:2
0

Giving the node USER permission to the package.json helped me.

COPY --chown=node:node package*.json .

in your case giving the node USER permission to package-lock.json should work as shown below:

COPY --chown=user:user package-lock.json .
New contributor
Samson Abosede is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.