Skip to content

Wrong npm version in GitHub actions #535

@svaraborut

Description

@svaraborut

With the introduction of Trusted Publishers it is now important to use npm >= 11 to avoid errors. Setting up a simple GH action

jobs:
  publish:
    runs-on: ubuntu-latest
    name: Release
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-node@v6
        with:
          node-version: '24'

      - run: npm -v
      - run: npx semantic-release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

And my release.config.js set like this:

export default {
        // ....
	plugins: [
                // ...
		[
			'@semantic-release/exec',
			{
				prepareCmd: 'npm -v'
			}
		]
	]
}

The logs will show two completely different npm versions 11.12.1 and 10.9.2. Attempting to explicitly set the shell with shell: '/bin/bash' or executing the command bash -c 'npm -v' does not solve the issue. My impression is that exec commands are running outside the execution environment set by the actions/setup-node@v6.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions