首页 > 解决方案 > 前后端同时使用时报错

问题描述

当我运行时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不存在,但我不知道为什么它首先会在那里寻找。

标签: node.jsvue.jsconcurrently

解决方案


原来是剧本!我不得不更改客户端脚本

"client": "npm run serve --prefix client"

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

推荐阅读