最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - EACCES error npm install with root privilege gitlab action - Stack Overflow

programmeradmin2浏览0评论

After I read this and many other github issue and stackoverflow, didn't find way to resolve it.
Error: EACCES: permission denied

I also read and tried this one as well, How to fix EACCES issues with npm install but the docker does not have sudo command and I tried whoami and it says "root" which means I already running with root privilege.

I have a action stage like this.

build-frontend:
  stage: build
  image: node:latest
  variables:
    NPM_CONFIG_PREFIX: ~/.npm-global  # Use a custom npm directory
  script:
    - mkdir -p ~/.npm-global
    - chmod -R 777 ~
    - chmod -R 777 . 
    - cd net-hr-report-frontend
    - npm ci || (chmod +x node_modules/esbuild/bin/esbuild && npm ci)
    - npm run build
    - echo "Build complete, check if backend has newest frontend changes"
    - git diff --exit-code

But the action log give give me this

Running with gitlab-runner 17.4.0 (b92ee590)
  on Gitlab Runner 2 JitPAe4N, system ID: s_5cb67d47bc0f
Preparing the "docker" executor
00:03
Using Docker executor with image node:latest ...
Pulling docker image node:latest ...
Using docker image sha256:1e7add1c04c7db775558644afde13b9e362a51fa6452cc617972147a70a7fba3 for node:latest with digest node@sha256:c65ab339c494443a7d2ed36140674bc8815f7100b0d4cebfe0144ce35267a693 ...
Preparing environment
00:01
Running on runner-jitpae4n-project-1254-concurrent-0 via gitlab-runner-2.dmz.xxxx.ca...
Getting source from Git repository
00:02
Fetching changes with git depth set to 20...
Reinitialized existing Git repository in /builds/*****/******/.git/
Checking out 515b5f82 as detached HEAD (ref is action)...
Skipping Git submodules setup
Restoring cache
00:01
Checking cache for default-non_protected...
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted. 
Successfully extracted cache
Executing "step_script" stage of the job script
00:10
Using docker image sha256:1e7add1c04c7db775558644afde13b9e362a51fa6452cc617972147a70a7fba3 for node:latest with digest node@sha256:c65ab339c494443a7d2ed36140674bc8815f7100b0d4cebfe0144ce35267a693 ...
$ mkdir -p ~/.npm-global
$ chmod -R 777 ~
$ chmod -R 777 .
$ cd frontend
$ npm ci || (chmod +x node_modules/esbuild/bin/esbuild && npm ci)
(node:18) ExperimentalWarning: CommonJS module /usr/local/lib/node_modules/npm/node_modules/debug/src/node.js is loading ES Module /usr/local/lib/node_modules/npm/node_modules/supports-color/index.js using require().
Support for loading ES Module in require() is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
npm error code 1
npm error path /builds/*****/******/frontend/node_modules/esbuild
npm error command failed
npm error command sh -c node install.js
npm error node:internal/child_process:1120
npm error     result.error = new ErrnoException(result.error, 'spawnSync ' + options.file);
npm error                    ^
npm error
npm error <ref *1> Error: spawnSync /builds/*****/******/frontend/node_modules/esbuild/bin/esbuild EACCES
npm error     at Object.spawnSync (node:internal/child_process:1120:20)
npm error     at spawnSync (node:child_process:868:24)
npm error     at Object.execFileSync (node:child_process:911:15)
npm error     at validateBinaryVersion (/builds/*****/******/frontend/node_modules/esbuild/install.js:99:28)
npm error     at /builds/*****/******/frontend/node_modules/esbuild/install.js:283:5 {
npm error   errno: -13,
npm error   code: 'EACCES',
npm error   syscall: 'spawnSync /builds/*****/******/frontend/node_modules/esbuild/bin/esbuild',
npm error   path: '/builds/*****/******/frontend/node_modules/esbuild/bin/esbuild',
npm error   spawnargs: [ '--version' ],
npm error   error: [Circular *1],
npm error   status: null,
npm error   signal: null,
npm error   output: null,
npm error   pid: 0,
npm error   stdout: undefined,
npm error   stderr: undefined
npm error }
npm error
npm error Node.js v23.2.0
npm error A complete log of this run can be found in: /root/.npm/_logs/2024-11-19T19_52_13_686Z-debug-0.log
chmod: cannot access 'node_modules/esbuild/bin/esbuild': No such file or directory
Cleaning up project directory and file based variables

I have tried multiple version of node including latest, 20, 18, and much more. I have tried use --allow-root to install all the dependecy, but it return the same error.
I have spent whole days in to this error, reading countless of postes relate to this issue but none of these post are like my issue. Most of the post I have read is about root prilivege, but the docker default use is root, and I check it with whoami. I tired to execute the npm install with su root -c, run chown, and none of these work.
I tried npm -g install but in the later stage, npm run build does not work saying that vite not found so I think I have to install the package locally.
I can run npm install on my local Windows machine but somehow not on the gitlab action. I believe the warning can be ignored because I saw the same warning when running npm install and still file.
I also upgrade all the depencency, so no more warning but error still remains.
I really haw no idea about this issue. I have done many node project and set up ci cd, but it is the first I see it.

This the the package.json file

{
  "name": "frontend",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite --mode development",
    "build": "vite build --mode production --emptyOutDir",
    "lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
    "preview": "vite preview"
  },
  "dependencies": {
    "@tanstack/react-query": "^5.40.1",
    "@vitejs/plugin-basic-ssl": "^1.1.0",
    "antd": "^5.19.0",
    "net-hr-contactinfo-frontend": "file:",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-router-dom": "^6.23.1"
  },
  "devDependencies": {
    "@types/react": "^18.2.66",
    "@types/react-dom": "^18.2.22",
    "@vitejs/plugin-react": "^4.2.1",
    "eslint": "^8.57.0",
    "eslint-plugin-react": "^7.34.1",
    "eslint-plugin-react-hooks": "^4.6.0",
    "eslint-plugin-react-refresh": "^0.4.6",
    "sass": "^1.77.4",
    "vite": "^5.2.0"
  }
}

发布评论

评论列表(0)

  1. 暂无评论