Home > database >  Why does NPM install require sudo to install everything?
Why does NPM install require sudo to install everything?

Time:09-22

I have a weird issue in my repo, that did work yesterday. When I run npm install it goes on without any issues, but the problem is that not all packages was installed. There are multiple modules that is missing in under node_modules/@types that I have defined in my packages.json.

I also miss some of the files that should be added to node_modules/bin, like nodemon. It does work if I run sudo npm install but that doesn't feel right.

I did update my npm and node version to latest lts, npm 6.14.15 and node 14.17.6.

My package.json looks like:

{
  "name": "blah",
  "version": "1.0.0",
  "description": "Blah blah blah",
  "author": "Tomas Jansson",
  "main": "./bin/index.js",
  "dependencies": {
    "@azure/arm-containerservice": "^13.3.0",
    "@azure/arm-subscriptions": "^3.1.0",
    "@azure/ms-rest-nodeauth": "^3.0.10",
    "@azure/msal-node": "^1.2.0",
    "@kubernetes/client-node": "^0.15.0",
    "@pulumi/azure-native": "^1.16.0",
    "@pulumi/azuread": "^4.3.0",
    "@pulumi/github": "^4.2.0",
    "@pulumi/kubernetes": "^3.5.1",
    "@pulumi/pulumi": "^3.7.0",
    "@pulumi/random": "^4.2.0",
    "@pulumi/tls": "^4.0.0",
    "cors": "^2.8.5",
    "dotenv": "^10.0.0",
    "express": "^4.17.1",
    "passport": "^0.4.1",
    "passport-azure-ad": "^4.3.0"
  },
  "devDependencies": {
    "@types/cors": "^2.8.12",
    "@types/express": "^4.17.13",
    "@types/node": "^16.3.2",
    "@types/passport-azure-ad": "^4.3.1",
    "nodemon": "^2.0.12",
    "ts-node": "^10.1.0",
    "typescript": "^4.3.5"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "tsc",
    "start": "node ./bin/index.js",
    "watch": "nodemon ./index.ts"
  }
}

Any ideas why I need to use sudo?

CodePudding user response:

It sounds like your user permissions for node_modules folder in your project are mismatched.

One possible way to fix this would be to remove the node_modules (using sudo) and then run npm install again. You should also verify your user is the owner of the project folder and the permissions from ls -l show you are allowed to read write.

A common reason this can happen if you're using Docker is that the user in the Docker container is likely root and the volume is being mapped between your host and container. You can change COPY commands to include a user:group such as COPY --chown=$USER_ID:$GROUP_ID app and pass these as build args to docker docker-compose build --build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g)

CodePudding user response:

so it deepness if the module is like (ffmpeg, nodemon or others) that are scripts that don't normally go in the runtime then you would need to use sudo but not all the time like using axios you would not need to use sudo to install, but if in doubt sudo it out.

  • Related