Sh: 1: webpack: not found

Problem to solve

gitlab ci failed build

$ npm run build
webpack
1: webpack: not found
Cleaning up project directory and file based variables00:00
ERROR: Job failed: command terminated with exit code 1

Steps to reproduce

Which troubleshooting steps have you already taken? Can you link to any docs or other resources so we know where you have been?

Configuration

.gitlab-ci.yml

build qa:
  stage: build
  extends:
    - .add-medium-runner-tag
    - .add-role-auth
  variables:
    DEPLOYMENT: qa
    NODE_ENV: production
    ROOT: qa/$CI_MERGE_REQUEST_ID
  before_script:
    # With NODE_ENV=production, clean up dev node modules
    - npm install
  script:
    - npm run build
  only:
    - merge_requests

package.json

"scripts": {
    "build": "webpack",
    "build:qa": "cross-env DEPLOYMENT=qa NODE_ENV=production webpack",
    ...
  },
"devDependencies": {
    ...
    "webpack": "^5.91.0",
    "webpack-cli": "^5.1.4",
}

### Versions 
$ npm -v
10.7.0
[node -v
v18.20.3

What’s the log output for this specific step in the executed CI/CD job? I would assume that it fails and webpack is not installed, causing the follow-up problem.

1 Like

what solution would you suggest?

I don’t know exactly what the root cause of problem is, hence my question to add more details for analysis :slight_smile:

1 Like

To help troubleshoot further, can you please add --loglevel verbose to the npm install and npm run build commands and share any relevant output or error messages (particularly interested in anything related to webpack). Thanks!

1 Like

There is clearly a problem with install. You can also check if modules were installed by ls -la node_modules.
Does NODE_ENV=production affect npm install in the way that it wont install dev dependencies? since webpack is in dev dependencies, that might be the reason why it was not installed.

You can also utilize npx

npx --yes webpack
1 Like