43 lines
1.1 KiB
Bash
43 lines
1.1 KiB
Bash
#!/bin/bash
|
|
# better-sqlite3 修复脚本
|
|
# 用于在部署目录重新编译 better-sqlite3 以匹配 pkg 的 Node.js 18
|
|
|
|
cd /opt/deploy || exit 1
|
|
|
|
echo "正在修复 better-sqlite3 原生模块..."
|
|
|
|
# 检查 package.json 是否存在
|
|
if [ ! -f "package.json" ]; then
|
|
echo "创建 package.json..."
|
|
cat > package.json << 'EOF'
|
|
{
|
|
"name": "remote-control-server",
|
|
"version": "1.0.3",
|
|
"dependencies": {
|
|
"better-sqlite3": "^11.10.0"
|
|
}
|
|
}
|
|
EOF
|
|
fi
|
|
|
|
# 安装依赖
|
|
echo "安装 better-sqlite3..."
|
|
npm install --production
|
|
|
|
# 重新编译 better-sqlite3 以匹配 Node.js 18 (NODE_MODULE_VERSION 108)
|
|
echo "重新编译 better-sqlite3 以匹配 Node.js 18..."
|
|
cd node_modules/better-sqlite3 || exit 1
|
|
|
|
# 使用 node-gyp 重新编译
|
|
npx node-gyp rebuild --target=18.0.0 --arch=x64 --target_platform=linux
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo "✅ better-sqlite3 重新编译成功!"
|
|
echo "现在可以运行 ./remote-control-server"
|
|
else
|
|
echo "❌ 重新编译失败,尝试使用 npm rebuild..."
|
|
cd /opt/deploy
|
|
npm rebuild better-sqlite3 --target=18 --target_arch=x64 --target_platform=linux
|
|
fi
|
|
|