node.js - 前后端同时使用时报错
问题描述
当我运行时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"
推荐阅读
- java - 在 Java 中授予 macOS 权限后运行 .command 文件
- java - 将数组列表转换为单个数组
- swift - 如何访问文本字段中的文本
- python - 如何使不和谐机器人能够多次播放 youtube 音频 (discord.py)
- java - 在执行期间向 JPanel 添加行
- xcode - Xcode Localization 中相同语言的两个选项,可供选择
- pytorch - AttributeError:模块“火炬”没有属性“设备”
- c++ - OpenGL 在多边形上绘制奇怪的线条
- ruby-on-rails - 具有自定义属性的 Rails JSON API 序列化程序
- python - 根据索引值的条件在 Pandas DataFrame 中选择行