skip to Main Content

I used vite to generate frontend template. The package.json is in the frontend directory and contains dev but i’m getting this error. the project is django and react. i’m using a python VE the backend runs with no issues. i installed the dependencies for react to the env so i don’t know :

{
  "name": "frontend",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
    "preview": "vite preview"
  },
  "dependencies": {
    "axios": "^1.6.8",
    "jwt-decode": "^4.0.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-router-dom": "^6.22.3",
    "react-scripts": "^3.0.1"
  },
  "devDependencies": {
    "@types/react": "^18.2.66",
    "@types/react-dom": "^18.2.22",
    "@vitejs/plugin-react": "^4.2.1",
    "eslint": "^8.57.0",
    "eslint-plugin-react": "^7.34.1",
    "eslint-plugin-react-hooks": "^4.6.0",
    "eslint-plugin-react-refresh": "^0.4.6",
    "vite": "^5.2.0"
  }
}

error:

(env) PS C:UsersAbdulDocumentsPersonal ProjectsAPI-testDjango&React FSfrontend> npm run dev

> [email protected] dev
> vite

'React' is not recognized as an internal or external command,
operable program or batch file.
node:internal/modules/cjs/loader:1146
  throw err;
  ^

Error: Cannot find module 'C:UsersAbdulDocumentsPersonal ProjectsAPI-testvitebinvite.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1143:15)
    at Module._load (node:internal/modules/cjs/loader:984:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
    at node:internal/main/run_main_module:28:49 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v20.12.1
(env) PS C:UsersAbdulDocumentsPersonal ProjectsAPI-testDjango&React FSfrontend> 

2

Answers


  1. You can install React and vite either globally or locally in your project using npm or yarn.

    • To install React globally: npm install -g react
    • To install React locally in your project: npm install react
    • To install Vite globally: npm install -g vite
    • To install Vite locally in your project: npm install vite

    After installing React and Vite, try running npm run dev again. If you’ve installed them locally, ensure that the paths to their binaries are correctly configured in your project’s package.json file.

    Login or Signup to reply.
  2. By the error logs you have provided it seems that you have a couple of issues,

    The first one is a misconfiguration of your package.json, specifically:

    'React' is not recognized as an internal or external command,

    However, at first glance I don’t see any apparent issues with your package.json.

    The second issue which is more likely to be the problem is:

    Error: Cannot find module 'C:UsersAbdulDocumentsPersonal ProjectsAPI-testvitebinvite.js'
    

    This indicates that the Vite package is either not installed or there is a path issue where node.js cannot find the ‘vite.js’ file.

    So, to resolve this I suggest you reinstall vite to ensure its installed correctly:

    npm install vite --save-dev
    

    Then, make sure your command line is open in your frontend directory and run:

    npm cache clean --force
    rm -rf node_modules
    npm install
    

    After that, you can try to run npm run dev again.

    Hope that helps.

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