yarnpkg / berry

📦🐈 Active development trunk for Yarn ⚒
https://yarnpkg.com
BSD 2-Clause "Simplified" License
7.43k stars 1.11k forks source link

[Bug?]: command `yarn workspaces focus --production` does not install all the dependencies #5079

Open hitech95 opened 1 year ago

hitech95 commented 1 year ago

Self-service

Describe the bug

I have a monorepo with 3 packages one of them depends on the other two (common, interfaces, api). Each package has its own 3rd party dependencies.

When I execture the command yarn workspaces focus --production it links/install only some of the dependencies. The root node_modules is empty and in the api's node_module directory there is no reference to the common and interfaces packages.

If I use instead yarn install all works fine but there a are a lot of "useless" dependencies installed aswell.

It is showing this issue also with external dependencies, for example:

/app # node packages/api/dist/index.js
internal/modules/cjs/loader.js:905
  throw err;
  ^

Error: Cannot find module 'source-map-support/register'
Require stack:
- /app/packages/api/dist/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:101:18)
    at Object.<anonymous> (/app/packages/api/dist/index.js:3:1)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/app/packages/api/dist/index.js' ]
}
/app #

To reproduce

he nodeLinker option in .yarnrc.yml is set to node-modules A simplified package.json are:

/package.json

{
  "name": "orgname",
  "workspaces": {
    "packages": [
      "packages/*"
    ]
  }, 
  "packageManager": "yarn@3.2.1",
  "devDependencies": {
    "lerna": "^6.0.0"
  }
}

/packages/common/package.json

{
  "name": "@orgname/common",
  "version": "0.1.1",
  "main": "dist/index.js",
  "types": "dist/index.d.ts",
  "files": [
    "/dist"
  ],
  "scripts": {
    "build": "yarn run build:clean && yarn run build:tsc",
    "build:clean": "rimraf dist && rimraf tsconfig.tsbuildinfo",
    "build:tsc": "tsc --build",
  },
  "dependencies": {
    "yup": "^0.32.0"
  },
  "devDependencies": {
    "@types/node": "^15.0.0",
    "@types/yup": "^0.29.0",
    "@typescript-eslint/eslint-plugin": "^5.26.0",
    "@typescript-eslint/parser": "^5.26.0",
    "eslint": "^8.16.0",
    "eslint-config-prettier": "^8.5.0",
    "eslint-plugin-jest": "^26.4.0",
    "eslint-plugin-prettier": "^4.0.0",
    "jest": "26.6.0",
    "jsdoc": "^3.6.0",
    "prettier": "^2.6.0",
    "rimraf": "^3.0.0",
    "typescript": "^4.2.0"
  }
}

/packages/api/package.json

{
  "name": "@orgname/api",
  "version": "0.1.0",
  "private": true,
  "bin": "dist/index.js",
  "main": "dist/index.js",
  "scripts": {
    "start": "babel-node -r dotenv/config src/index.js",
    "start:dev": "cross-env NODE_ENV=development babel-node -r dotenv/config src/index.js",
    "start:watch": "nodemon",
  },
  "dependencies": {
    "@orgname/common": "0.1.1",
    "@orgname/interfaces": "1.0.0",
    "axios": "^0.27.0",
    "bcryptjs": "^2.4.3",
    "cors": "^2.8.5",
    "dotenv": "^16.0.0",
    "express": "^4.18.0",
    "express-session": "^1.17.0",
    "helmet": "^6.0.0",
    "source-map-support": "^0.5.0",
    "yup": "^0.32.0"
  },  
  "devDependencies": {
    "@babel/cli": "^7.12.8",
    "@babel/core": "^7.7.2",
    "@babel/node": "^7.7.0",
    "babel-jest": "26.6.3",
    "babel-plugin-source-map-support": "^2.1.3",
    "cross-env": "^7.0.3",
    "eslint": "^8.16.0",
    "eslint-config-prettier": "^8.5.0",
    "eslint-plugin-jest": "^26.4.0",
    "eslint-plugin-prettier": "^4.0.0",
    "jest": "26.6.0",
    "jsdoc": "^3.6.0",
    "nodemon": "^2.0.7",
    "pkg": "^5.8.0",
    "prettier": "^2.6.0",
    "rimraf": "^3.0.0"
  }
}

Environment

System:
    OS: Linux 5.10 Alpine Linux
    CPU: (2) x64 Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz
  Binaries:
    Node: 14.21.1 - /tmp/xfs-4816e34a/node
    Yarn: 3.2.1 - /tmp/xfs-4816e34a/yarn
    npm: 6.14.17 - /usr/local/bin/npm

Additional context

No response

tetrasmolyn commented 1 year ago

I am also seeing this issue

blephy commented 1 year ago

No issue here when using like yarn workspaces focus --production @scope/my-package from the root cwd. Yarn install (like it should do) only manifest.dependencies field for the given workspace. This is the right way for production usage. I never seen this issue from yarn@^3.2.0 to yarn@^3.3.0 for my part.