nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.24k stars 2.31k forks source link

nx-release-publish fails after upgrading to 19.5.X #27440

Open or-orchid opened 1 month ago

or-orchid commented 1 month ago

Current Behavior

After upgrading NX to 19.5.X, the publish command fails

>  nx release publish --dry-run --verbose
Based on your config, the following projects were matched for publishing but do not have the "nx-release-publish" target specified:

- eslint-plugin
- healthcheck
- common
- logger
- redis
- test

This is usually caused by not having an appropriate plugin, such as "@nx/js" installed, which will add the appropriate "nx-release-publish" target for you automatically.

Expected Behavior

Should publish libs

GitHub Repo

No response

Steps to Reproduce

  1. Install nx:19.4.3
  2. Run nx release publish --dry-run --verbose and see that the packages should be published
  3. run nx migrate 19.5.7
  4. run nx migrate --run-migrations --if-exists
  5. Run nx release publish --dry-run --verbose and see the errors

Nx Report

➜  nodejs-core git:(main) ✗ nx report

 NX   Report complete - copy this into the issue template

Node           : 20.10.0
OS             : darwin-arm64
Native Target  : aarch64-macos
npm            : 10.8.2

nx                 : 19.5.7
@nx/js             : 19.5.7
@nx/jest           : 19.5.7
@nx/linter         : 19.5.7
@nx/eslint         : 19.5.7
@nx/workspace      : 19.5.7
@nx/devkit         : 19.5.7
@nx/eslint-plugin  : 19.5.7
@nx/nest           : 19.5.7
@nx/node           : 19.5.7
@nx/plugin         : 19.5.7
@nrwl/tao          : 19.5.7
typescript         : 5.5.4
---------------------------------------
Registered Plugins:
@nx/eslint/plugin
@nx/jest/plugin
---------------------------------------
Community plugins:
@nx-aws-plugin/nx-aws-cache : 3.2.1

Failure Logs

This is usually caused by not having an appropriate plugin, such as "@nx/js" installed, which will add the appropriate "nx-release-publish" target for you automatically.

    at runPublishOnProjects (/Users/orgaizer/repos/nodejs-core/node_modules/nx/src/command-line/release/publish.js:127:15)
    at releasePublish (/Users/orgaizer/repos/nodejs-core/node_modules/nx/src/command-line/release/publish.js:72:30)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at handleErrors (/Users/orgaizer/repos/nodejs-core/node_modules/nx/src/utils/params.js:22:24)
    at Object.handler (/Users/orgaizer/repos/nodejs-core/node_modules/nx/src/command-line/release/command-object.js:185:24)

Package Manager Version

10.8.2

Operating System

Additional Information

I suspect it's related to this PR

JamesHenry commented 1 month ago

Please share your nx.json contents and any "release" or "nx-release-publish" config found in project.json files

or-orchid commented 4 weeks ago

@JamesHenry Hey,attached

{
  "pluginsConfig": {
    "@nx/js": {
      "analyzeSourceFiles": true
    }
  },
  "$schema": "./node_modules/nx/schemas/nx-schema.json",
  "extends": "nx/presets/npm.json",
  "namedInputs": {
    "default": ["{projectRoot}/**/*", "sharedGlobals"],
    "production": [
      "default",
      "!{projectRoot}/.eslintrc.json",
      "!{projectRoot}/eslint.config.js",
      "!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)",
      "!{projectRoot}/tsconfig.spec.json",
      "!{projectRoot}/jest.config.[jt]s",
      "!{projectRoot}/src/test-setup.[jt]s",
      "!{projectRoot}/test-setup.[jt]s"
    ],
    "sharedGlobals": []
  },
  "defaultBase": "main",
  "plugins": [
    {
      "plugin": "@nx/eslint/plugin",
      "options": {
        "targetName": "lint"
      }
    },
    {
      "plugin": "@nx/jest/plugin",
      "options": {
        "targetName": "test"
      },
      "exclude": ["test-e2e/**/*", "apps/test-e2e/**/*"]
    },
    {
      "plugin": "@nx/webpack/plugin",
      "options": {
        "buildTargetName": "build",
        "serveTargetName": "serve",
        "previewTargetName": "preview"
      }
    }
  ],
  "targetDefaults": {
    "@nx/js:tsc": {
      "cache": true,
      "dependsOn": ["^build"],
      "inputs": ["production", "^production"],
      "outputs": ["{options.outputPath}"],
      "options": {
        "outputPath": "dist/{projectRoot}",
        "tsConfig": "{projectRoot}/tsconfig.lib.json",
        "packageJson": "{projectRoot}/package.json",
        "main": "{projectRoot}/src/index.ts"
      }
    },
    "@nx/js:eslint": {
      "cache": true,
      "dependsOn": ["^build"],
      "inputs": ["default", "^default"],
      "outputs": ["{options.outputFile}"],
      "options": {
        "lintFilePatterns": [
          "{projectRoot}/**/*.{ts,tsx,js,jsx}",
          "{projectRoot}/package.json"
        ]
      }
    },
    "@nx/jest:jest": {
      "cache": true,
      "dependsOn": ["^build"],
      "inputs": ["default", "^default"],
      "outputs": ["{options.outputFile}"],
      "options": {
        "jestConfig": "{projectRoot}/jest.config.ts"
      }
    },
    "@nx/js:swc": {
      "dependsOn": ["^build"],
      "cache": true,
      "inputs": ["production", "^production"],
      "outputs": ["{options.outputPath}"],
      "options": {
        "outputPath": "dist/{projectRoot}",
        "main": "{projectRoot}/src/index.ts",
        "tsConfig": "{projectRoot}/tsconfig.lib.json",
        "assets": []
      }
    },
    "install": {
      "inputs": ["{projectRoot}/package.json"],
      "outputs": [
        "{projectRoot}/node_modules",
        "{projectRoot}/package-lock.json"
      ],
      "executor": "nx:run-commands",
      "options": {
        "command": "npm install",
        "cwd": "{projectRoot}"
      }
    },
    "ci": {
      "inputs": [
        "{projectRoot}/package.json",
        "{projectRoot}/package-lock.json"
      ],
      "outputs": ["{projectRoot}/node_modules"],
      "executor": "nx:run-commands",
      "options": {
        "command": "npm ci",
        "cwd": "{projectRoot}"
      }
    },
    "nx-release-publish": {
      "options": {
        "packageRoot": "dist/{projectRoot}"
      }
    }
  },
  "release": {
    "projects": ["*", "!source"],
    "projectsRelationship": "independent",
    "releaseTagPattern": "{projectName}/v{version}",
    "version": {
      "preVersionCommand": "npx nx run-many -t build",
      "generatorOptions": {
        "packageRoot": "{projectRoot}",
        "skipLockFileUpdate": false,
        "fallbackCurrentVersionResolver": "disk"
      },
      "conventionalCommits": true
    },
    "git": {
      "commitMessage": "chore: release [skip ci]"
    },
    "changelog": {
      "automaticFromRef": true,
      "projectChangelogs": true,
      "workspaceChangelog": false
    }
  },
  "tasksRunnerOptions": {
    "default": {
      "options": {
        "cacheableOperations": []
      }
    },
    "ci": {
      "runner": "@nx-aws-plugin/nx-aws-cache",
      "options": {
        "cacheableOperations": [],
        "awsRegion": "eu-central-1",
        "awsForcePathStyle": true
      }
    },
    "local": {
      "runner": "@nx-aws-plugin/nx-aws-cache",
      "options": {
        "cacheableOperations": [],
        "awsRegion": "eu-central-1",
        "awsForcePathStyle": true
      }
    }
  }
}

as for project.json, there isn't any release or nx-release-publish config found there. Also according to the error message above, nx/js plugin should inject the nx-release-publish config to the project.json automatically

This is usually caused by not having an appropriate plugin, such as "@nx/js" installed, which will add the appropriate "nx-release-publish" target for you automatically.

or-orchid commented 4 weeks ago

This code should handle it for package.json based libs. I can't find the equivalent for project.json https://github.com/nrwl/nx/blob/b91d78809e9ef88744fefa90b66903216f134ba3/packages/nx/src/utils/package-json.ts#L186

JamesHenry commented 4 weeks ago

@or-orchid are you saying that those libraries do not have a package.json file in their project root?

or-orchid commented 4 weeks ago

@JamesHenry This is our dir structure

.
├── README.md
├── commitlint.config.ts
├── jest.config.ts
├── jest.preset.js
├── libs
│   ├── redis
│   │   ├── CHANGELOG.md
│   │   ├── jest.config.ts
│   │   ├── package-lock.json
│   │   ├── package.json
│   │   ├── project.json
│   │   ├── src
│   │   ├── tsconfig.json
│   │   ├── tsconfig.lib.json
│   │   └── tsconfig.spec.json
├── migrations.json
├── nx.json
├── package-lock.json
├── package.json
├── tsconfig.base.json
├── tsconfig.build.json
└── tsconfig.json

redis/package.json

{
  "name": "@XXXXX/redis",
  "repository": {
    "type": "git",
    "url": "https://github.com/XXXXXX/YYYYY.git"
  },
  "version": "0.3.3",
  "type": "commonjs",
  "main": "./src/index.js",
  "typings": "./src/index.d.ts",
  "publishConfig": {
    "access": "restricted"
  },
  "peerDependencies": {
    "@nestjs/common": "^10.3.10",
    "@nestjs/config": "^3.1.1"
  },
  "dependencies": {
    "ioredis": "^5.4.0"
  },
  "devDependencies": {}
}

redis/project.json

{
  "name": "redis",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "libs/redis/src",
  "projectType": "library",
  "tags": [],
  "targets": {
    "build": {
      "executor": "@nx/js:swc"
    },
    "tsc": {
      "executor": "@nx/js:tsc"
    },
    "lint": {
      "dependsOn": ["ci"],
      "executor": "@nx/eslint:lint"
    },
    "test": {
      "dependsOn": ["ci"],
      "executor": "@nx/jest:jest",
      "options": {
        "passWithNoTests": true
      }
    },
    "install": {},
    "ci": {}
  }
}
github-actions[bot] commented 2 weeks ago

This issue has been automatically marked as stale because more information has not been provided within 7 days. It will be closed in 21 days if no information is provided. If information has been provided, please reply to keep it active. Thanks for being a part of the Nx community! 🙏

or-orchid commented 2 weeks ago

Bump

github-actions[bot] commented 1 week ago

This issue has been automatically marked as stale because more information has not been provided within 7 days. It will be closed in 21 days if no information is provided. If information has been provided, please reply to keep it active. Thanks for being a part of the Nx community! 🙏

JamesHenry commented 1 week ago

@or-orchid Sorry for the delay, but as you can appreciate, things always go much faster if you take the time to provide a minimal reproduction repo for us to investigate.

I am now taking the time to manually recreate the outline you have listed

JamesHenry commented 1 week ago

What is the reason for having a nested lock file? Are you running a fully independent install command within that nested directory?

JamesHenry commented 1 week ago

Are you not using npm workspaces? These two points make a big difference here so I cannot continue further.

If you can provide a minimal reproduction repo that will naturally be most time efficient, but otherwise please provide clear guidance on how your package management concerns are set up.

thdk commented 1 week ago

And a minimal repro: https://github.com/thdk/nx-repro-nx-release-publish-target-missing

Contains only a single project and configuration for nx release in nx.json.


Node           : 22.2.0
OS             : darwin-arm64
Native Target  : aarch64-macos
npm            : 10.8.0

nx                 : 19.6.5
@nx/js             : 19.6.5
@nx/linter         : 19.6.5
@nx/eslint         : 19.6.5
@nx/workspace      : 19.6.5
@nx/devkit         : 19.6.5
@nx/eslint-plugin  : 19.6.5
@nrwl/tao          : 19.6.5
typescript         : 5.5.4
---------------------------------------
Registered Plugins:
@nx/eslint/plugin

UPDATE: this repro didn't contain any library created with the --publishable flag and therefor the release publish command was failing with the error.

 NX   Your filter "tag:type:package" matched the following projects:

- some-lib

 NX   Based on your config, the following projects were matched for publishing but do not have the "nx-release-publish" target specified:

- some-lib

This is usually caused by not having an appropriate plugin, such as "@nx/js" installed, which will add the appropriate "nx-release-publish" target for you automatically.
JamesHenry commented 1 week ago

@thdk Thank you for repro. In this case it’s because you have marked the library as private, which means it is not publishable, so there is correctly no associated target

https://github.com/thdk/nx-repro-nx-release-publish-target-missing/blob/51c841bd79c46230970c10b5adc6174abf1c46ec/some-lib/package.json#L10

thdk commented 1 week ago

@JamesHenry thanks for spotting the issue!

I actually used the interactive approach to generate the library and I haven't been prompted to tell if the generate library should be publishable or not. My bad here. Do you think it would make sense to at that options to the interactive prompts? I could try to submit a PR for that :)

tianbaolin commented 6 days ago

I also encountered this issue and need help.