在使用 electron-builder 构建 exe 后找不到模块 'sqlite3'

cannot find module 'sqlite3' after build exe with electron-builder

我在 https://medium.com/jspoint/packaging-and-distributing-electron-applications-using-electron-builder-311fc55178d9

的帮助下构建了我的电子应用程序

这是成功的(仅 windows)。但在安装已发布的应用程序后,出现如屏幕截图所示的错误

我的脚本如下

package.json

  "name": "aux-services",
  "version": "1.0.0",
  "description": "Mobile Repair Tracking System",
  "main": "main.js",
  "scripts": {
    "start": "electron .",
    "postinstall": "electron-builder install-app-deps",
      "pack": "electron-builder -w"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/shafeequeot/Mobile-Service-Tracker.git"
  },
  "author": "AuxWall",
  "email": "shafeequeot@gmail.com",
  "url": "https://auxwall.com",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/shafeequeot/Mobile-Service-Tracker/issues"
  },
  "homepage": "https://github.com/shafeequeot/Mobile-Service-Tracker#readme",
  "devDependencies": {
    "electron": "^11.1.1",
    "electron-builder": "^22.14.13",
    "sqlite3": "^5.0.2"
  },
  "dependencies": {
   
  }
}

电子-builder.json

{
    "appId": "com.auxWall.service",

    "productName": "Aux Services",
    "copyright": "AuxWall",
    "directories": {
        "app": ".",
        "output": "out",
        "buildResources": "build-res"
    },
    "files": [
        "package.json",
        "**/*",
        "node_modules"
    ],
    "dmg": {
        "background": null,
        "backgroundColor": "#ffffff",
        "window": {
            "width": "400",
            "height": "300"
        },
        "contents": [
            {
                "x": 100,
                "y": 100
            },
            {
                "x": 300,
                "y": 100,
                "type": "link",
                "path": "/Applications"
            }
        ]
    },
    "mac": {
        "target": "dmg",
        "category": "public.auxWall.services"
      },
    "win": {
        "target": "nsis"
    },
    "linux": {
        "target": "AppImage",
        "category": "Utility"
    }
}

谁能帮我解决这个问题?

如果在 Electron 应用程序的正常运行期间需要 sqlite3 而不仅仅是在开发期间,那么您将需要添加 sqlite3 作为依赖项。

IE:将 "sqlite3": "^5.0.2""devDependencies": { ... } 移动到 "dependencies": { ... }

package.json

{
  "name": "aux-services",
  "version": "1.0.0",
  "description": "Mobile Repair Tracking System",
  "main": "main.js",
  "scripts": {
    "start": "electron .",
    "postinstall": "electron-builder install-app-deps",
      "pack": "electron-builder -w"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/shafeequeot/Mobile-Service-Tracker.git"
  },
  "author": "AuxWall",
  "email": "shafeequeot@gmail.com",
  "url": "https://auxwall.com",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/shafeequeot/Mobile-Service-Tracker/issues"
  },
  "homepage": "https://github.com/shafeequeot/Mobile-Service-Tracker#readme",
  "devDependencies": {
    "electron": "^11.1.1",
    "electron-builder": "^22.14.13"
  },
  "dependencies": {
    "sqlite3": "^5.0.2"   
  }
}