'Gitlab CI Failed: NPM command not found
I have been playing around Gitlabl CI but for some reason I can't get my tests to "passed". It always says npm: command not found
My Gitlab CI config looks like this:
image: node:latest
# This folder is cached between builds
# http://docs.gitlab.com/ce/ci/yaml/README.html#cache
cache:
paths:
- node_modules/
before_script:
- npm install
- npm install eslint -g
- npm install eslint-plugin-react -g
- npm install babel-eslint -g
test:lint:
script:
- eslint src/*
I keep getting the error below and I have No Idea why:

By the way, Im NOT using the gitlab shared runner. Not sure if that contributes to the problem but just to make sure, the machine that has my gitlab runner has all the necessary packages to run nodejs.
Your help is greatly appreciated
Best regards,
Solution 1:[1]
The image tag specifies a docker image, hence you must specify the executor of your runner to be docker. Did you perhaps set it to be something else, like shell, when you created the runner?
Solution 2:[2]
You can use like below:-
stages:
- build
- deploy
deploy-prod:
image: node:12.13.0-alpine
stage: deploy
script:
- npm i -g firebase-tools
Solution 3:[3]
I have same problem.
Gitlab-runner use user of 'gitlab-runner' default when it starts. So the user have not root access.
ps aux|grep gitlab-runner
copy the shell of running
change user: run
/usr/bin/gitlab-runner run --working-directory /home/gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --syslog --user rootin bash.gitlab-ci runner test
pass!
kill old pid
nohup /usr/bin/gitlab-runner run --working-directory /home/gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --syslog --user root
ps: gitlab-runner -u root also change user.
Solution 4:[4]
Your cli is taking ssh executer by default. You probably need docker. Try adding tag in your yml script.
tags: [ <your docker image name> ]
Solution 5:[5]
In my case, there are two gitlab-runner. There is no node enviroment in the specific Runner.Then I stopped the wrong one
Solution 6:[6]
This helped me:
n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Amposter |
| Solution 2 | Obsidian Age |
| Solution 3 | ??? |
| Solution 4 | |
| Solution 5 | Alan-Wen |
| Solution 6 | Lajos Arpad |
