/bin/bash: line 131: npm: command not found

i dont know how to resolve my problem,
" Running after script…
npm i npx
/bin/bash: line 131: npm: command not found"
this is my .gitlab-ci.yml

image: node:16.14.2
cache:
  paths:
    - node_modules/
stages:
  - deploy
deploy:dev:
  image: ruby:latest
  stage: deploy
  variables:
    APP_NAME: $HEROKU_APP_NAME_DEV
    HEROKU_API_KEY: $HEROKU_API_KEY
  before_script:
    - apt-get update -qy
    - apt-get install -y ruby-dev
    - gem install dpl
  script:
    - dpl --provider=heroku --app=$APP_NAME --api-key=$HEROKU_API_KEY
  after_script:
    - apt-get install -g npx
    - npx migrate-mongo up

this is my log capture from gitlab
log

I’m wondering whether this is really the job that produces that log?

In your deploy:dev job you are running on a ruby:latest Docker container (which overrides image:node:16.14.2). You shouldn’t need to install ruby-dev in your before_script for that job, because your image is a Ruby image. You should just be able to say:

    before_script:
        - gem install dpl

Then in your after_script, you don’t have a line that says npm i npx that you show in the log?

Hi, tnx for your help.
I have this yml now

image: node:16.14.2
cache:
  paths:
    - node_modules/
stages:
  - deploy
deploy:dev:
  image: ruby:latest
  stage: deploy
  variables:
    APP_NAME: $HEROKU_APP_NAME_DEV
    HEROKU_API_KEY: $HEROKU_API_KEY
  before_script:
    - apt-get update -qy
    - gem install dpl
    - npm install
  script:
    - dpl --provider=heroku --app=$APP_NAME --api-key=$HEROKU_API_KEY
  after_script:
    - npm i npx
    - npm i migrate-mongo
    - npx migrate-mongo up
  only:
    - /^dev-.*$/

logs

I think you need to change your before_script to install everything you need later on, like this:

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

Thank you it is working now but gitlab does not recognize my environment variables.

Oh, I missed that.

This section:

  variables:
    APP_NAME: $HEROKU_APP_NAME_DEV
    HEROKU_API_KEY: $HEROKU_API_KEY

Should be for creating variables, I’m not sure that you can rename them like this. It would be much easier to remove the variables section and change your script:

  ...
  script:
    - dpl --provider=heroku --app=$HEROKU_APP_NAME_DEV --api-key=$HEROKU_API_KEY