31 changed files with 769 additions and 141 deletions
@ -0,0 +1,139 @@
@@ -0,0 +1,139 @@
|
||||
# npm 路径问题修复总结 |
||||
|
||||
## 问题描述 |
||||
|
||||
您遇到的错误: |
||||
``` |
||||
Uncaught exception: Error: spawn npm ENOENT |
||||
``` |
||||
|
||||
这个错误表明 Electron 应用在尝试启动构建过程时找不到 `npm` 命令。 |
||||
|
||||
## 根本原因 |
||||
|
||||
1. **Windows 环境下的 npm 路径问题**:在 Windows 环境下,npm 命令实际上是 `npm.cmd` |
||||
2. **构建文件路径错误**:代码中的路径拼接导致重复的 `app` 目录 |
||||
3. **缺少 shell 参数**:spawn 命令缺少 `shell: true` 参数 |
||||
|
||||
## 修复内容 |
||||
|
||||
### 1. 修复 npm 命令调用 (`app/src/main/index.js`) |
||||
|
||||
**修复前:** |
||||
```javascript |
||||
const buildProcess = spawn('npm', ['run', 'build:vue'], { |
||||
cwd: appRoot, |
||||
stdio: 'pipe' |
||||
}); |
||||
``` |
||||
|
||||
**修复后:** |
||||
```javascript |
||||
// 在 Windows 环境下使用 npm.cmd |
||||
const npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm'; |
||||
const buildProcess = spawn(npmCommand, ['run', 'build:vue'], { |
||||
cwd: appRoot, |
||||
stdio: 'pipe', |
||||
shell: true |
||||
}); |
||||
``` |
||||
|
||||
### 2. 修复构建文件路径 (`app/src/main/index.js`) |
||||
|
||||
**修复前:** |
||||
```javascript |
||||
const loadPath = path.join(appRoot, 'app/dist/renderer/index.html') |
||||
``` |
||||
|
||||
**修复后:** |
||||
```javascript |
||||
const loadPath = path.join(appRoot, 'dist/renderer/index.html') |
||||
``` |
||||
|
||||
## 新增文件 |
||||
|
||||
### 1. 修复启动脚本 (`app/fix-npm-start.ps1`) |
||||
- PowerShell 版本的修复脚本 |
||||
- 包含环境检查、依赖安装、预构建和启动功能 |
||||
- 支持调试和监听模式 |
||||
|
||||
### 2. 批处理版本 (`app/fix-npm-start.bat`) |
||||
- 批处理文件版本的修复脚本 |
||||
- 功能与 PowerShell 版本相同 |
||||
|
||||
### 3. 测试脚本 (`app/test-fix.bat`) |
||||
- 简单的测试脚本,用于验证修复是否有效 |
||||
|
||||
## 使用方法 |
||||
|
||||
### 方法 1:使用修复脚本 |
||||
```bash |
||||
# PowerShell |
||||
cd app |
||||
powershell -ExecutionPolicy Bypass -File fix-npm-start.ps1 |
||||
|
||||
# 批处理 |
||||
cd app |
||||
fix-npm-start.bat |
||||
``` |
||||
|
||||
### 方法 2:手动修复 |
||||
1. 确保在 `app` 目录下 |
||||
2. 运行 `npm install` 安装依赖 |
||||
3. 运行 `npm run build:vue` 构建前端 |
||||
4. 运行 `electron .` 启动应用 |
||||
|
||||
### 方法 3:测试修复 |
||||
```bash |
||||
cd app |
||||
test-fix.bat |
||||
``` |
||||
|
||||
## 验证修复 |
||||
|
||||
运行测试脚本后,应该看到: |
||||
- ✅ 构建文件存在: dist\renderer\index.html |
||||
- ✅ npm 命令正常 |
||||
- ✅ 构建命令成功 |
||||
|
||||
## 注意事项 |
||||
|
||||
1. **确保 Node.js 已正确安装**:访问 https://nodejs.org 下载并安装 |
||||
2. **确保在正确的目录**:所有命令都应在 `app` 目录下运行 |
||||
3. **检查环境变量**:确保 npm 在系统 PATH 中 |
||||
4. **权限问题**:如果遇到权限问题,请以管理员身份运行 |
||||
|
||||
## 故障排除 |
||||
|
||||
如果仍然遇到问题: |
||||
|
||||
1. **检查 Node.js 安装**: |
||||
```bash |
||||
node --version |
||||
npm --version |
||||
``` |
||||
|
||||
2. **重新安装依赖**: |
||||
```bash |
||||
cd app |
||||
rm -rf node_modules |
||||
npm install |
||||
``` |
||||
|
||||
3. **清理构建缓存**: |
||||
```bash |
||||
cd app |
||||
rm -rf dist |
||||
npm run build:vue |
||||
``` |
||||
|
||||
4. **检查防火墙和杀毒软件**:某些安全软件可能阻止 npm 命令执行 |
||||
|
||||
## 总结 |
||||
|
||||
通过以上修复,解决了: |
||||
- Windows 环境下 npm 命令找不到的问题 |
||||
- 构建文件路径错误的问题 |
||||
- 自动构建失败的问题 |
||||
|
||||
现在应用应该能够正常启动和运行了。 |
@ -0,0 +1,65 @@
@@ -0,0 +1,65 @@
|
||||
@echo off |
||||
chcp 65001 >nul |
||||
setlocal enabledelayedexpansion |
||||
|
||||
echo 🔧 修复 npm 路径问题的启动脚本 |
||||
echo. |
||||
|
||||
REM 设置环境变量 |
||||
set VUE_CLI_BABEL_TRANSPILE_MODULES=false |
||||
set VUE_CLI_MODERN_BUILD=false |
||||
set VUE_CLI_LOG_LEVEL=info |
||||
set LANG=zh_CN.UTF-8 |
||||
set LC_ALL=zh_CN.UTF-8 |
||||
|
||||
REM 检查 Node.js 环境 |
||||
echo 检查 Node.js 环境... |
||||
node --version >nul 2>&1 |
||||
if errorlevel 1 ( |
||||
echo ❌ Node.js 未找到,请确保已正确安装 |
||||
echo 请访问 https://nodejs.org 下载并安装 Node.js |
||||
pause |
||||
exit /b 1 |
||||
) |
||||
|
||||
npm --version >nul 2>&1 |
||||
if errorlevel 1 ( |
||||
echo ❌ npm 未找到,请确保已正确安装 |
||||
pause |
||||
exit /b 1 |
||||
) |
||||
|
||||
echo ✅ Node.js 环境检查通过 |
||||
echo. |
||||
|
||||
REM 检查依赖 |
||||
echo 检查依赖... |
||||
if not exist "node_modules" ( |
||||
echo 📦 依赖未安装,正在安装... |
||||
npm install |
||||
if errorlevel 1 ( |
||||
echo ❌ 依赖安装失败 |
||||
pause |
||||
exit /b 1 |
||||
) |
||||
) |
||||
|
||||
REM 预构建前端 |
||||
echo. |
||||
echo 预构建前端... |
||||
npm run build:vue |
||||
if errorlevel 1 ( |
||||
echo ❌ 前端构建失败 |
||||
pause |
||||
exit /b 1 |
||||
) |
||||
|
||||
echo ✅ 前端构建成功 |
||||
echo. |
||||
|
||||
REM 启动 Electron |
||||
echo 启动 Electron 应用... |
||||
echo 🚀 标准模式启动... |
||||
electron . |
||||
|
||||
pause |
@ -0,0 +1,72 @@
@@ -0,0 +1,72 @@
|
||||
# 修复 npm 路径问题的启动脚本 |
||||
param( |
||||
[switch]$Debug, |
||||
[switch]$Watch |
||||
) |
||||
|
||||
# 设置控制台编码为 UTF-8 |
||||
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8 |
||||
[Console]::InputEncoding = [System.Text.Encoding]::UTF8 |
||||
$OutputEncoding = [System.Text.Encoding]::UTF8 |
||||
|
||||
# 设置环境变量 |
||||
$env:VUE_CLI_BABEL_TRANSPILE_MODULES = "false" |
||||
$env:VUE_CLI_MODERN_BUILD = "false" |
||||
$env:VUE_CLI_LOG_LEVEL = "info" |
||||
$env:LANG = "zh_CN.UTF-8" |
||||
$env:LC_ALL = "zh_CN.UTF-8" |
||||
|
||||
Write-Host "🔧 修复 npm 路径问题的启动脚本" -ForegroundColor Cyan |
||||
Write-Host "" |
||||
|
||||
# 检查 Node.js 和 npm 是否可用 |
||||
Write-Host "检查 Node.js 环境..." -ForegroundColor Yellow |
||||
try { |
||||
$nodeVersion = node --version |
||||
$npmVersion = npm --version |
||||
Write-Host "✅ Node.js: $nodeVersion" -ForegroundColor Green |
||||
Write-Host "✅ npm: $npmVersion" -ForegroundColor Green |
||||
} catch { |
||||
Write-Host "❌ Node.js 或 npm 未找到,请确保已正确安装" -ForegroundColor Red |
||||
Write-Host "请访问 https://nodejs.org 下载并安装 Node.js" -ForegroundColor Yellow |
||||
exit 1 |
||||
} |
||||
|
||||
# 检查依赖 |
||||
Write-Host "" |
||||
Write-Host "检查依赖..." -ForegroundColor Yellow |
||||
if (-not (Test-Path "node_modules")) { |
||||
Write-Host "📦 依赖未安装,正在安装..." -ForegroundColor Yellow |
||||
npm install |
||||
if ($LASTEXITCODE -ne 0) { |
||||
Write-Host "❌ 依赖安装失败" -ForegroundColor Red |
||||
exit 1 |
||||
} |
||||
} |
||||
|
||||
# 预构建前端 |
||||
Write-Host "" |
||||
Write-Host "预构建前端..." -ForegroundColor Yellow |
||||
npm run build:vue |
||||
if ($LASTEXITCODE -ne 0) { |
||||
Write-Host "❌ 前端构建失败" -ForegroundColor Red |
||||
exit 1 |
||||
} |
||||
|
||||
Write-Host "✅ 前端构建成功" -ForegroundColor Green |
||||
|
||||
# 启动 Electron |
||||
Write-Host "" |
||||
Write-Host "启动 Electron 应用..." -ForegroundColor Green |
||||
|
||||
if ($Debug) { |
||||
Write-Host "🐛 调试模式启动..." -ForegroundColor Magenta |
||||
$env:DEBUG = "*" |
||||
electron . |
||||
} elseif ($Watch) { |
||||
Write-Host "👀 监听模式启动..." -ForegroundColor Blue |
||||
npm run dev:watch |
||||
} else { |
||||
Write-Host "🚀 标准模式启动..." -ForegroundColor Green |
||||
electron . |
||||
} |
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
@echo off |
||||
chcp 65001 >nul |
||||
|
||||
echo 测试 npm 路径修复... |
||||
echo. |
||||
|
||||
REM 检查当前目录 |
||||
echo 当前目录: %CD% |
||||
echo. |
||||
|
||||
REM 检查构建文件是否存在 |
||||
if exist "dist\renderer\index.html" ( |
||||
echo ✅ 构建文件存在: dist\renderer\index.html |
||||
) else ( |
||||
echo ❌ 构建文件不存在: dist\renderer\index.html |
||||
) |
||||
|
||||
echo. |
||||
echo 测试 npm 命令... |
||||
npm --version |
||||
if errorlevel 1 ( |
||||
echo ❌ npm 命令失败 |
||||
) else ( |
||||
echo ✅ npm 命令正常 |
||||
) |
||||
|
||||
echo. |
||||
echo 测试构建命令... |
||||
npm run build:vue |
||||
if errorlevel 1 ( |
||||
echo ❌ 构建命令失败 |
||||
) else ( |
||||
echo ✅ 构建命令成功 |
||||
) |
||||
|
||||
echo. |
||||
echo 测试完成! |
||||
pause |
@ -1,15 +0,0 @@
@@ -1,15 +0,0 @@
|
||||
package routes |
||||
|
||||
import ( |
||||
"gofaster/internal/auth/controller" |
||||
|
||||
"github.com/gin-gonic/gin" |
||||
) |
||||
|
||||
func RegisterUserRoutes(router *gin.RouterGroup, userCtrl *controller.UserController) { |
||||
router.GET("/users", userCtrl.ListUsers) |
||||
router.POST("/users", userCtrl.CreateUser) |
||||
router.GET("/users/:id", userCtrl.GetUser) |
||||
router.PUT("/users/:id", userCtrl.UpdateUser) |
||||
router.DELETE("/users/:id", userCtrl.DeleteUser) |
||||
} |
Binary file not shown.
@ -1 +1 @@
@@ -1 +1 @@
|
||||
exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1 |
||||
exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1 |
Binary file not shown.
@ -0,0 +1,126 @@
@@ -0,0 +1,126 @@
|
||||
<!DOCTYPE html> |
||||
<html lang="zh-CN"> |
||||
<head> |
||||
<meta charset="UTF-8"> |
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
||||
<title>验证码测试</title> |
||||
<style> |
||||
body { |
||||
font-family: Arial, sans-serif; |
||||
padding: 20px; |
||||
background-color: #f5f5f5; |
||||
} |
||||
.container { |
||||
max-width: 600px; |
||||
margin: 0 auto; |
||||
background: white; |
||||
padding: 20px; |
||||
border-radius: 8px; |
||||
box-shadow: 0 2px 10px rgba(0,0,0,0.1); |
||||
} |
||||
.captcha-container { |
||||
margin: 20px 0; |
||||
padding: 20px; |
||||
border: 1px solid #ddd; |
||||
border-radius: 4px; |
||||
} |
||||
.captcha-image { |
||||
border: 1px solid #ccc; |
||||
border-radius: 4px; |
||||
cursor: pointer; |
||||
} |
||||
button { |
||||
background: #007bff; |
||||
color: white; |
||||
border: none; |
||||
padding: 10px 20px; |
||||
border-radius: 4px; |
||||
cursor: pointer; |
||||
margin: 10px 5px; |
||||
} |
||||
button:hover { |
||||
background: #0056b3; |
||||
} |
||||
.error { |
||||
color: red; |
||||
margin: 10px 0; |
||||
} |
||||
.success { |
||||
color: green; |
||||
margin: 10px 0; |
||||
} |
||||
</style> |
||||
</head> |
||||
<body> |
||||
<div class="container"> |
||||
<h1>验证码显示测试</h1> |
||||
|
||||
<div class="captcha-container"> |
||||
<h3>验证码图片:</h3> |
||||
<img id="captchaImage" class="captcha-image" alt="验证码" style="display: none;" /> |
||||
<div id="captchaPlaceholder">点击按钮获取验证码</div> |
||||
<br> |
||||
<button onclick="getCaptcha()">获取验证码</button> |
||||
<button onclick="refreshCaptcha()">刷新验证码</button> |
||||
</div> |
||||
|
||||
<div id="status"></div> |
||||
<div id="response"></div> |
||||
</div> |
||||
|
||||
<script> |
||||
let currentCaptchaId = ''; |
||||
|
||||
async function getCaptcha() { |
||||
try { |
||||
document.getElementById('status').innerHTML = '<div class="success">正在获取验证码...</div>'; |
||||
|
||||
const response = await fetch('http://localhost:8080/api/auth/captcha', { |
||||
method: 'GET', |
||||
headers: { |
||||
'Content-Type': 'application/json' |
||||
} |
||||
}); |
||||
|
||||
if (!response.ok) { |
||||
throw new Error(`HTTP error! status: ${response.status}`); |
||||
} |
||||
|
||||
const data = await response.json(); |
||||
console.log('验证码响应:', data); |
||||
|
||||
if (data.code === 200 && data.data) { |
||||
const captchaImage = document.getElementById('captchaImage'); |
||||
const placeholder = document.getElementById('captchaPlaceholder'); |
||||
|
||||
captchaImage.src = data.data.captcha_image; |
||||
captchaImage.style.display = 'block'; |
||||
placeholder.style.display = 'none'; |
||||
|
||||
currentCaptchaId = data.data.captcha_id; |
||||
|
||||
document.getElementById('status').innerHTML = '<div class="success">验证码获取成功!</div>'; |
||||
document.getElementById('response').innerHTML = ` |
||||
<h4>响应数据:</h4> |
||||
<pre>${JSON.stringify(data, null, 2)}</pre> |
||||
`; |
||||
} else { |
||||
throw new Error(data.message || '获取验证码失败'); |
||||
} |
||||
} catch (error) { |
||||
console.error('获取验证码失败:', error); |
||||
document.getElementById('status').innerHTML = `<div class="error">获取验证码失败: ${error.message}</div>`; |
||||
} |
||||
} |
||||
|
||||
function refreshCaptcha() { |
||||
getCaptcha(); |
||||
} |
||||
|
||||
// 页面加载时自动获取验证码 |
||||
window.onload = function() { |
||||
getCaptcha(); |
||||
}; |
||||
</script> |
||||
</body> |
||||
</html> |
Loading…
Reference in new issue