command not found: webpack in yarn Berry monorepo

183 Views Asked by At

Working on a yarn 3.6.x monorepo with multiple workspaces spread over 2 different folders i do get an error when invoking scripts in the workspaces. I do not have this issue locally, also not when checking the repository out from scratch. Though other team members and in our build pipeline i do face this issue.

The workspaces can be divided in local config packages and apps. App workspaces have (dev)Dependencies to the local config workspaces. Simplified the repo structure resembles:

.
├── apps
│   ├── cancel
│       ├── .eslintrc.js
│       ├── package.json
│       ├── src
│       └── webpack.config.js
│   └── leisure
│       ├── .eslintrc.js
│       ├── package.json
│       ├── src
│       └── webpack.config.js
├── configs
│   ├── eslint
│   │   ├── config
│   │   ├── index.js
│   │   └── package.json
│   └── webpack
│       ├── config
│       └── package.json
├── package.json
└── yarn.lock

The package.json at the root level of the project is;

{
  "name": "@myorg/monorepo",
  "version": "1.0.0",
  "private": true,
  "description": "Products",
  "license": "ISC",
  "scripts": {
    "all:build": "yarn workspaces foreach --include @anwb/account-products-cancel --include @anwb/account-products-leisure --parallel run build",
    "all:lint": "yarn workspaces foreach --verbose --parallel run lint",
  },
  "workspaces": [
    "apps/cancel",
    "apps/leisure",
    "configs/eslint",
    "configs/webpack"
  ],
  "devDependencies": {
 ...
  },
  "packageManager": "[email protected]",
  "team": "Mijn Org",
  "title": "Monorepo setup"
}

The app package.json scripts are similar to:

{
    "name": "@anwb/account-products-leisure",
    "sideEffects": false,
    "version": "1.5.0",
    "private": true,
    "description": "Account Products Leisure",
    "license": "ISC",
    "scripts": {
        "build": "webpack --mode=production",
        "lint": "eslint --fix --ext .ts,.tsx src",
    },
    "dependencies": {
...
        "react": "17.0.2",
        "react-dom": "17.0.2",
        "styled-components": "^5.3.6"
    },
    "devDependencies": {
        "@anwb/style-utilities": "^4.10.0",
        "@anwb/test-utils": "^3.0.1",
        "prettier": "2.6.2",
        "puppeteer": "^13.1.3",
        "react": "17.0.2",
        "react-dom": "17.0.2",
        "react-select-event": "^5.5.1",
        "sonarqube-scanner": "2.8.1",
        "standard-version": "9.3.2",
        "webpack-bundle-analyzer": "^4.8.0"
    },
    "team": "Mijn Org",
    "title": "Products Cancel"
}

When running locally yarn all:build or yarn all:lint the scripts complete successful. But when executed on other systems or in Gitlab i do get the error;

$ yarn all:lint
[@myorg/products-cancel]: Process started
[@myorg/products-leisure]: Process started
[@myorg/products-cancel]: command not found: eslint
[@myorg/products-cancel]: Process exited (exit code 127), completed in 0s 759ms
[@myorg/products-leisure]: command not found: eslint
[@myorg/products-leisure]: Process exited (exit code 127), completed in 0s 743ms
Done in 0s 762ms

Same issue when building the workspaces, where webpack is not found. Webpack and eslint are in the root node_modules folder

update 1 Found the cause, locally i am used to run yarn in the integrated terminal session of my IDE. In this terminal session the monorepo/node_modules/.bin is added to the path. When running in a separate terminal (macOS) or gitlab pipeline, the location of node_modules/.bin is not added to path.

0

There are 0 best solutions below