我使用vite生成前端模板。 package.json 位于前端目录中并包含 dev 但我收到此错误。该项目是django和react。我正在使用 python VE,后端运行没有问题。我安装了对环境做出反应的依赖项,所以我不知道:
{
"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"
}
}
错误:
(env) PS C:\Users\Abdul\Documents\Personal Projects\API-test\Django&React FS\frontend> 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:\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>
您可以使用npm或yarn在项目中全局或本地安装React和vite。
安装 React 和 Vite 后,尝试再次运行 npm run dev。如果您已在本地安装它们,请确保在项目的 package.json 文件中正确配置了其二进制文件的路径。