同时使用前端和后端运行时出错

问题描述

当我运行 npm run dev 时,我收到此错误

[1] npm ERR! code ENOENT
[1] npm ERR! syscall open
[1] npm ERR! path C:\Users\reaga\Desktop\Projects\weather-app-v3\api\client/package.json   
[1] npm ERR! errno -4058
[1] npm ERR! enoent ENOENT: no such file or directory,open 'C:\Users\reaga\Desktop\Projects\weather-app-v3\api\client\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
[1] npm ERR! enoent
[1]
[1] npm ERR! A complete log of this run can be found in:
[1] npm ERR!     C:\Users\reaga\AppData\Local\npm-cache\_logs\2021-02-24T21_11_36_564Z-debug.log
[1] npm ERR! code 4294963238
[1] npm ERR! path C:\Users\reaga\Desktop\Projects\weather-app-v3\api
[1] npm ERR! command Failed
[1] npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c npm run serve --prefix client    
[1] 
[1] npm ERR! A complete log of this run can be found in:
[1] npm ERR!     C:\Users\reaga\AppData\Local\npm-cache\_logs\2021-02-24T21_11_37_020Z-debug.log

我有一个包含 Vue 应用程序的客户端文件夹,与我的 api 文件夹位于同一目录中,该文件夹包含后端。

当我在正确的目录中单独运行启动脚本时,每个脚本都可以完美运行。这是我的脚本:

  "scripts": {
    "start": "node server","server": "nodemon server","client": "npm run serve --prefix client","dev": "concurrently \"npm run server\" \"npm run client\""
  }

我知道 C:\Users\reaga\Desktop\Projects\weather-app-v3\api\client/package.json 不存在,但我不知道为什么它首先会在那里寻找。

解决方法

原来是剧本!我不得不从

更改客户端脚本
"client": "npm run serve --prefix client"

"client": "cd ../client && npm run serve"