Gitlab CI Failed: NPM command not found
Asked Answered
F

8

16

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: enter image description here

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,

Flare answered 26/6, 2017 at 7:11 Comment(6)
A naive question, but do you have node.js installed on your gitlab runner?Selfinterest
Can you figure out under which OS account gitlab runner executes tests? After that you could try to login to that account and verify if npm is available.Selfinterest
@Selfinterest Yes- as I mentioned the machine that has my gitlab runner has everything to run nodejs. That means I have nodejs installed. Thank you fFlare
@Selfinterest it's under root account. On my runner.ssh I specify user as the root and Yes- it has nodejs installed too.Flare
Maybe npm is not in in the PATH of root user?Selfinterest
@Selfinterest it does. Just to make sure I also installed nodejs under gitlab-runner and added it to sudo groupFlare
A
8

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?

Achilles answered 9/10, 2017 at 15:56 Comment(1)
In my case I was using ssh instead of docker.Message
M
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
Marsala answered 19/4, 2020 at 16:27 Comment(0)
P
0

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

  1. copy the shell of running

  2. change user: run /usr/bin/gitlab-runner run --working-directory /home/gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --syslog --user root in bash.

  3. gitlab-ci runner test

  4. pass!

  5. kill old pid

  6. 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.

Puri answered 11/5, 2018 at 4:40 Comment(0)
M
0

This helped me:

n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local
Module answered 10/7, 2020 at 13:0 Comment(0)
E
0

Your cli is taking ssh executer by default. You probably need docker. Try adding tag in your yml script.

 tags: [ <your docker image name> ]
Elwoodelwyn answered 18/2, 2021 at 9:23 Comment(0)
N
0

If you are using sshpass to pass some command to your server, you'll have to update your .bashrc file (file path: ~/.bashrc).

In .bashrc file you see following code uncommented, comment it and it resolve your issue.

case $- in
    *i*) ;;
      *) return;;
esac
Nahuatl answered 11/12, 2023 at 11:30 Comment(0)
B
0

This worked greatly for me

    before_script:
    - apt-get update -qy
    - apt-get install --no-install-recommends -y npm
    - npm --version
    - npx --version
    - gem install dpl
    - npm install

Source: https://forum.gitlab.com/t/bin-bash-line-131-npm-command-not-found/70632/3

Blaine answered 7/3 at 21:29 Comment(0)
N
-1

In my case, there are two gitlab-runner. There is no node enviroment in the specific Runner.Then I stopped the wrong one

Noellenoellyn answered 29/3, 2022 at 10:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.