我试图同时使用来运行后端和前端,我尝试过了,但由于没有正确使用脚本,它给了我错误。
我在后台包中同时使用.json
>backend
all the backend files and package.json file for node js
>frontend
all the frontend files and package.json file for react js
脚本
"scripts": {
"start": "nodemon server.js",
"start-server": "npm start --prefix backend",
"start-client": "npm start --prefix frontend",
"dev": "concurrently " npm run start-server" " npm run start-client""
},
npm run dev
> backend@1.0.0 dev
> concurrently " npm run start-server" " npm run start-client"
[0]
[0] > backend@1.0.0 start-server
[0] > npm start --prefix backend
[0]
[1]
[1] > backend@1.0.0 start-client
[1] > npm start --prefix frontend
[1]
[0] npm ERR! code ENOENT
[0] npm ERR! syscall open
[0] npm ERR! path C:UsershpDocumentsReact_Projectsreact-mui-nodebackendbackend/package.json
[0] npm ERR! errno -4058
[0] npm ERR! enoent ENOENT: no such file or directory, open 'C:UsershpDocumentsReact_Projectsreact-mui-nodebackendbackendpackage.json'
[0] npm ERR! enoent This is related to npm not being able to find a file.
[0] npm ERR! enoent
[0]
[0] npm ERR! A complete log of this run can be found in:
[0] npm ERR! C:UsershpAppDataLocalnpm-cache_logs2022-09-15T01_15_58_352Z-debug-0.log
[1] npm ERR! code ENOENT
[1] npm ERR! syscall open
[1] npm ERR! path C:UsershpDocumentsReact_Projectsreact-mui-nodebackendfrontend/package.json
[1] npm ERR! errno -4058
[1] npm ERR! enoent ENOENT: no such file or directory, open 'C:UsershpDocumentsReact_Projectsreact-mui-nodebackendfrontendpackage.json'
[1] npm ERR! enoent This is related to npm not being able to find a file.
[1] npm ERR! enoent
[0] npm run start-server exited with code 4294963238
[1]
[1] npm ERR! A complete log of this run can be found in:
npm ERR! C:UsershpAppDataLocalnpm-cache_logs2022-09-15T01_15_58_389Z-debug-0.log
[1] npm run start-client exited with code 4294963238
这只是一个目录问题,我以为我在当前目录中,但没有修复这个代码的问题
"dev": "concurrently "cd ../frontend && npm start" "cd ../backend && npm start""