Skip to content

InvalidPackageVersionError: Package version must be a string, got "undefined" #160

Closed
@michaelnlindsay

Description

@michaelnlindsay

Hello! Not sure how I arrived at this particular error. I believe these are the salient parts of my workflow file:

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}
          registry-url: ${{ env.NPM_REGISTRY_URL }}

      - name: Build
        run: |
          npm install
          npm run build

      - name: Test
        run: |
          npm test

      - uses: JS-DevTools/npm-publish@v3
        with:
          token: ${{ secrets.NPM_TOKEN }}
          registry: ${{ env.NPM_REGISTRY_URL }}
          tag: "v${{ steps.version.outputs.value }}-${{ env.BETA_SUFFIX }}"
          dry-run: true

Can you spot what I may be missing?

Activity

michaelnlindsay

michaelnlindsay commented on Oct 24, 2023

@michaelnlindsay
Author

NB: I do have a package.json file in the root directory that has 'version' field, returned by steps.version.outputs.value

mcous

mcous commented on Oct 24, 2023

@mcous
Member

What is the value of the version field in your package.json? This error could occur if the value is not valid semver.

Also, that usage of the tag input looks suspicious. The meaning is npm's dist-tag, not the package version

Also also, is that publish step running inside a matrix? If so, that's a bad idea! Might just be a copy paste issue

mcous

mcous commented on Oct 24, 2023

@mcous
Member

@michaelnlindsay it looks like this is your package.json version:

{
  "version": "2.11.2a",
}

2.11.2a is not a valid semantic version, and all packages published to npm must follow semver. I have opened #161 to improve the error message to something more helpful:

InvalidPackageVersionError: Package version must be a valid semantic version, got "2.11.2.a"
added a commit that references this issue on Oct 24, 2023
0807712
michaelnlindsay

michaelnlindsay commented on Oct 24, 2023

@michaelnlindsay
Author

Brilliant! Managed to land myself on the new error message too. Looks good, I understand what it's complaining about especially with inclusion of the version I supplied. It worked like a charm after I stopped trying to provide tag, any value give for that, even proper semvar, was throwing errors. Which is probably fine? Shouldn't need it anyway? Thanks for the swift response! Much appreciated :)

mcous

mcous commented on Oct 24, 2023

@mcous
Member

As mentioned above, tag should not be a version. The default value of tag is latest, as in:

npm install example@latest

The purpose of tag is to create "release channels" of a sort. For example, you may publish canary versions that shouldn't be installed by default, but you could use:

with:
  tag: canary

To publish versions that can be installed via:

npm install example@canary
michaelnlindsay

michaelnlindsay commented on Oct 24, 2023

@michaelnlindsay
Author

Got it... I was obviously experimenting off the range, sorry about that. tag will be useful to me there then :D and canary is an excellent suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @mcous@michaelnlindsay

      Issue actions

        InvalidPackageVersionError: Package version must be a string, got "undefined" · Issue #160 · JS-DevTools/npm-publish