skip to Main Content

I am struggling to run my react js project using npm run dev, which was created using vite. Whenever I run it using npm run dev it says, npm ERR! Missing script: "dev" and I have installed npm and vite already.

I have vite and dev in my package.json file

2

Answers


  1. Please copy your package.json file, so that anyone can understand and answer the question better way.

    Your package.json file must include this code.

    {
      "scripts": {
        "dev": "vite",
        "build": "vite build",
        "preview": "vite preview"
      }
    }
    
    Login or Signup to reply.
  2. When you install Vite (with npm create vite@latest, found on Vite’s set up guide) and Node.js/NPM, a package.json file is created which, when done using Vite, should automatically set up the dev, build and preview scripts inside package.json. An example of a package.json file created with Vite is below:

    {
      "name": "project",
      "private": true,
      "version": "0.0.0",
      "type": "module",
      "scripts": {
        "dev": "vite", //Dev script, set up automatically by Vite
        "build": "vite build", //Build script, set up automatically by Vite
        "preview": "vite preview" //Preview script, set up automatically by Vite
      },
      "dependencies": {
      },
      "devDependencies": {
      }
    }
    

    You won’t be able to start your Vite project using npm run dev unless you’ve either added the dev script yourself or created your Vite project using npm create vite@latest. Just having NPM and Vite installed isn’t enough if you don’t have a working package.json file.

    Showing the content of your package.json file however would be helpful to check if these scripts are inside. You can edit your question to include this.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search