JS-DevTools / npm-publish

GitHub Action to publish to NPM
https://jstools.dev/npm-publish
MIT License
620 stars 74 forks source link

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

Closed michaelnlindsay closed 1 year ago

michaelnlindsay commented 1 year ago

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 commented 1 year ago

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

mcous commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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.