EACCES: permission denied for package-lock.json
Asked Answered
S

3

6

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??

Superimposed answered 16/4, 2022 at 9:56 Comment(3)
see: Resolving lockfile conflictsSelf
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.Indirection
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.Streptokinase
E
2

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.

Evieevil answered 2/11, 2023 at 19:42 Comment(0)
B
1

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

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

In your case, giving the user permission to package-lock.json file should work as shown below:

COPY --chown=user:user package-lock.json .
Bordie answered 14/7 at 9:52 Comment(0)
Z
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
Zorazorah answered 9/5, 2023 at 10:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.