I am encountering an error when trying to run the command npm run dev. How can I resolve
I utilized vite to create a frontend template. The package.json resides in the frontend directory and includes development tools, but I'm encountering an error. This project involves Django and React. I am using a Python virtual environment, and the backend is running smoothly. I have also installed React dependencies in the environment, so I am unsure of what the issue could be.
{
"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:\Users\Abdul\Documents\Personal Projects\API-test\Django&React FS\frontend> npm run dev
> <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7117031e1f05141f1531415f415f41">[email protected]</a> 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:\Users\Abdul\Documents\Personal Projects\API-test\vite\bin\vite.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:\Users\Abdul\Documents\Personal Projects\API-test\Django&React FS\frontend>
Try https://reacter.space/questions/i-am-encountering-an-error-when-trying-to-run-the-command-npm-run-dev-how-can-i-resolve
Did you run npm install before running the project if not run npm install. If already installed delete node modules folder and rerun npm install
Run npm commands in correct file. Run npm install inside your project folder
built an app to get paid for this PR https://www.n0va-io.com/discover/facebook/react
It seems your node packages aren't installed properly, or aren't installed at all.
You should try deleting node_modules folder if there is any then run npm install in your project directory then you can retry your npm run dev command.
you should try to delete the node_modules folder and then run the npm i in your project, after that run the npm run dev
``1. Check React Installation 2.Remove react-scripts (If Using Vite) 3. Reinstall Node Modules 4. Ensure Vite is Installed Properly 5. Check for Correct Scripts in package.json 6. Vite Configuration File 7. Check Node.js Version 8. Clear npm Cache (if needed)
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!