Error deploying with Netlify-cli in GitLab CI: Cannot find module netlify-cli/scripts/postinstall.js'

I’m trying to deploy my Gatsby website to Netlify as the last step of my GitLab CI/CD pipeline, and I get “Cannot find module netlify-cli/scripts/postinstall.js” error during the deployment process.

Error trace:

 $ npx netlify-cli deploy --site $NETLIFY_SITE_ID --auth $NETLIFY_AUTH_TOKEN --prod
 internal/modules/cjs/loader.js:1023
   throw err;
   ^
 Error: Cannot find module '/root/.npm/_npx/36/lib/node_modules/netlify-cli/scripts/postinstall.js'
 at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1020:15)
 at Function.Module._load (internal/modules/cjs/loader.js:890:27)
 at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
 at internal/main/run_main_module.js:17:47 {
   code: 'MODULE_NOT_FOUND',
   requireStack: []
 }

This is my .gitlab-ci.yml configuration:

image: node:latest

cache:
  untracked: true
  paths:
    - node_modules/

stages:
  - build
  - deploy


build:
  stage: build
  script:
    - npm install
    - ./node_modules/.bin/gatsby build --prefix-paths
  artifacts:
    paths:
      - public
  only:
    - merge_requests
    - master

deploy:
  stage: deploy
  script:
    - npm i -g netlify-cli
    - npx netlify-cli deploy --site $NETLIFY_SITE_ID --auth $NETLIFY_AUTH_TOKEN --prod
  dependencies:
    - build
  only:
    - master

Do you know how to solve this problem?

Thanks!

Solved, I was running “netlify-cli” instead “netlify”:

It works:

npx netlify deploy --site $NETLIFY_SITE_ID --auth $NETLIFY_AUTH_TOKEN --prod