5

Is there a way to update the version number of my react app package.json version variable via command line? Maybe with npm build or before/after npm build?

I have a build server that will run npm build and then deploy to production. I want to be able to update the version number of my application either during the build process or before it as part of the build pipeline. I am planning to just use the last git commit sha as the version number.

Is there a command that I am missing? I have had a look at npm version but I believe that is for just updating packages. I could be wrong.

3
  • 1
    you mean the semver management command npm version (major|minor|patch)? Commented Nov 25, 2021 at 22:51
  • @Mike'Pomax'Kamermans does this allow me to set a unique version or just increment the semantic version? Commented Nov 25, 2021 at 22:55
  • If you're using npm, you should absolutely only ever use semver. If you need build numbers, that's what patch is for (and if you need build dates, that's in the tag commit and trivial to look up) Commented Nov 25, 2021 at 23:19

2 Answers 2

1

You can use,

npm version [major|minor|patch]

to bump the version variable on package.json using cli.

If you want to combine it with the build, you can use;

npm version [major|minor|patch] && react-scripts build

References

  1. npmjs.com for syntax documentation.
  2. semvar.org for version notation.
Sign up to request clarification or add additional context in comments.

1 Comment

note that this is typically pretty useless, because you'll have tagged the current commit, after which you run your build, so how your tag points to the code as it existed before you rebuilt it.
0
npm version [major|minor|patch] 

if you get "npm ERR! Git working directory not clean." you should

npm version [major|minor|patch] --no-git-tag-version

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.