Search code examples
reactjsnpmvite

What is the difference between npm init vite@latest and npm init vite?


I recently started using vite to make my react apps as I grew tired of the excruciatingly long install times for create-react-app. However, as I looked online, I found different ways of making a vite app. On the official documentation, it says to use npm init vite@latest while other tutorials use npm init vite. Both require you to install different dependencies on your machine before you can run the commands. However, it appears that they both do essentially the same thing. Can anyone explain the difference between the 2 commands?


Solution

  • The difference between the two, is, npm init vite@latest will download the latest version - and npm init vite will use create-vite if you had it previously globally installed, or it will fetch the latest version. that's it. Read below 👇

    When you get @latest on some tutorials, you can see it as an explicit information in order to not confuse the reader, but they should stipulate the following note.

    Note:

    IF you had already the create-vite package globally installed, and for example, a older version, it will be what npm init uses.

    So:

    npm init foo fetches and runs the already installed create-foo OR the latest create-foo from the registry if not.

    npm init foo@latest fetches and runs the latest create-foo from the registry.

    npm init [email protected] runs [email protected] to install the package version 1.2.3 specifically.