Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
michaelnlindsay opened this issue Oct 24, 2023 · 6 comments · Fixed by #161
Closed

Comments

@michaelnlindsay
Copy link

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?

@michaelnlindsay
Copy link
Author

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

@mcous
Copy link
Member

mcous commented Oct 24, 2023

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
Copy link
Member

mcous commented Oct 24, 2023

@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"

@michaelnlindsay
Copy link
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
Copy link
Member

mcous commented Oct 24, 2023

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
Copy link
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
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants