热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ElectronJs:请手动安装sqlite3包

如何解决《ElectronJs:请手动安装sqlite3包》经验,为你挑选了1个好方法。

我试图sqliteelectron应用程序配置数据库,安装sqlite依赖后我开始收到错误请手动安装sqlite3包.我重复了几次相同的步骤但是sqlite没有用electron

我只是通过互联网搜索这个问题,我发现了几个答案,但每个答案都缺少步骤.因此,在这个问题上花了我4个工作日后,我想出了一个包含所有详细步骤的可靠解决方案.希望它能为其他人节省时间



1> UFFAN..:

如果您收到错误找不到节点模块sqlite3electron在安装后手动在应用程序中安装sqlite3包sqlite.然后,此解决方案可以帮助解决您的问题.

第1步:我们需要在您的本地克隆电子快速启动项目

来源:https://electronjs.org/docs/tutorial/first-app

$ git clone https://github.com/electron/electron-quick-start

第2步:进入存储库

$ cd electron-quick-start

第3步:安装electronJs依赖项

$ npm install

第4步:运行电子项目

$ npm start

现在让我们来看看最挑战的部分

第5步:现在我们需要安装sqlite依赖项

$ npm install sqlite3 --save
$ npm install sequelize --save

步骤6:在IDE中打开main.js并在文件末尾添加此代码以创建数据库连接

资料来源:http://docs.sequelizejs.com/manual/installation/usage.html

// Create database connection
const Sequelize = require('sequelize');
    const sequelize = new Sequelize('database', 'username', 'password', {
    host: 'localhost',
    dialect: 'sqlite',
    operatorsAliases: false,
    pool: {
        max: 5,
        min: 0,
        acquire: 30000,
        idle: 10000
    },
    storage: './database.sqlite'
});

// Test connection
sequelize
    .authenticate()
    .then(() => {
        console.log('Connection has been established successfully.');
    })
    .catch(err => {
        console.error('Unable to connect to the database:', err);
    });

第7步:现在再次启动您的电子项目npm start,您将开始获得异常

Error: Please install sqlite3 package manually
我们如何解决它?

第8步:要修复此错误,我们需要安装电子重建包.在执行此命令之前,请确保使用cmd 以管理员身份运行,否则它将无法运行.

$ npm install --save-dev electron-rebuild

步骤9:现在我们必须package.json在脚本下配置rebuild命令

"scripts": {
    "rebuild": "electron-rebuild -f -w sqlite3"
}

第10步:现在我们需要安装python并将其设置为环境变量中的Path.

下载Python:https://www.python.org/download/releases/2.7/

打开控制面板>系统和安全>系统>高级系统设置>环境变量

"%username% "的" 用户变量"部分下,单击"新建"以添加新项

设置变量名Path和变量值C:\Python27(已安装python的位置),然后单击OK按钮

步骤10:现在打开一个新命令行并重建您的电子项目

$ npm run rebuild

第11步:现在你可以运行它,它将正常工作

$ npm start

快乐的编程.


注意:如果在运行时在步骤10中出现此错误 npm run rebuild

× Rebuild Failed

An unhandled error occurred inside electron-rebuild
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
MSBUILD : error MSB3428: Could not load the Visual C++ component "VCBuild.exe". To fix this, 1) install the .NET Framework 2.0 SDK, 2) install Microsoft Visual Studio 2005 or 3) add the location of the component to the system path if it is installed elsewhere.  [C:\Projects\Test\node_modules\sqlite3\build\binding.sln]
gyp ERR! build error
gyp ERR! stack Error: `C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Projects\Test\node_modules\node-gyp\lib\build.js:262:23)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Projects\\Test\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--target=1.8.8" "--arch=x64" "--dist-url=https://atom.io/download/electron" "--build-from-source" "--module_name=node_sqlite3" "--module_path=C:\\Projects\\Test\\node_modules\\sqlite3\\lib\\binding\\electron-v1.8-win32-x64" "--host=https://mapbox-node-binary.s3.amazonaws.com" "--remote_path=./{name}/v4.0.2/{toolset}/" "--package_name=electron-v1.8-win32-x64.tar.gz"
gyp ERR! cwd C:\\Projects\\Test\node_modules\sqlite3
gyp ERR! node -v v6.9.5
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok

Failed with exit code: 1

Error: Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
MSBUILD : error MSB3428: Could not load the Visual C++ component "VCBuild.exe". To fix this, 1) install the .NET Framework 2.0 SDK, 2) install Microsoft Visual Studio 2005 or 3) add the location of the component to the system path if it is installed elsewhere.  [C:\Projects\Test\node_modules\sqlite3\build\binding.sln]
gyp ERR! build error
gyp ERR! stack Error: `C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Projects\Test\node_modules\node-gyp\lib\build.js:262:23)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Projects\\Test\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--target=1.8.8" "--arch=x64" "--dist-url=https://atom.io/download/electron" "--build-from-source" "--module_name=node_sqlite3" "--module_path=C:\\Projects\\Test\\node_modules\\sqlite3\\lib\\binding\\electron-v1.8-win32-x64" "--host=https://mapbox-node-binary.s3.amazonaws.com" "--remote_path=./{name}/v4.0.2/{toolset}/" "--package_name=electron-v1.8-win32-x64.tar.gz"
gyp ERR! cwd C:\\Projects\\Test\node_modules\sqlite3
gyp ERR! node -v v6.9.5
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok

Failed with exit code: 1
    at SafeSubscriber._error (C:\Projects\Test\node_modules\spawn-rx\lib\src\index.js:277:84)
    at SafeSubscriber.__tryOrUnsub (C:\Projects\Test\node_modules\rxjs\Subscriber.js:242:16)
    at SafeSubscriber.error (C:\Projects\Test\node_modules\rxjs\Subscriber.js:201:26)
    at Subscriber._error (C:\Projects\Test\node_modules\rxjs\Subscriber.js:132:26)
    at Subscriber.error (C:\Projects\Test\node_modules\rxjs\Subscriber.js:106:18)
    at MapSubscriber.Subscriber._error (C:\Projects\Test\node_modules\rxjs\Subscriber.js:132:26)
    at MapSubscriber.Subscriber.error (C:\Projects\Test\node_modules\rxjs\Subscriber.js:106:18)
    at SafeSubscriber._next (C:\Projects\Test\node_modules\spawn-rx\lib\src\index.js:251:65)
    at SafeSubscriber.__tryOrSetError (C:\Projects\Test\node_modules\rxjs\Subscriber.js:251:16)
    at SafeSubscriber.next (C:\Projects\Test\node_modules\rxjs\Subscriber.js:191:27)

然后在命令行中执行此操作 npm install windows-build-tools --global

安装时windows-build-tools如果你得到这个例外

async function aquireInstallers(cb) {
      ^^^^^^^^
SyntaxError: Unexpected token function
    at Object.exports.runInThisContext (vm.js:76:16)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object. (C:\Users\User\AppData\Roaming\npm\node_modules\windows-build-tools\dist\start.js:4:29)

这意味着你使用的是旧版本的的NodeJS修复它,你可以安装旧版本的Windows的构建工具使用npm install windows-build-tools@2.2.1 --global

现在您可以使用启动项目了 npm start


推荐阅读
  • 本文详细介绍了如何在Linux系统上安装和配置Smokeping,以实现对网络链路质量的实时监控。通过详细的步骤和必要的依赖包安装,确保用户能够顺利完成部署并优化其网络性能监控。 ... [详细]
  • 1.如何在运行状态查看源代码?查看函数的源代码,我们通常会使用IDE来完成。比如在PyCharm中,你可以Ctrl+鼠标点击进入函数的源代码。那如果没有IDE呢?当我们想使用一个函 ... [详细]
  • 本文详细介绍了 Dockerfile 的编写方法及其在网络配置中的应用,涵盖基础指令、镜像构建与发布流程,并深入探讨了 Docker 的默认网络、容器互联及自定义网络的实现。 ... [详细]
  • 解决PHP与MySQL连接时出现500错误的方法
    本文详细探讨了当使用PHP连接MySQL数据库时遇到500内部服务器错误的多种解决方案,提供了详尽的操作步骤和专业建议。无论是初学者还是有经验的开发者,都能从中受益。 ... [详细]
  • 前言--页数多了以后需要指定到某一页(只做了功能,样式没有细调)html ... [详细]
  • DNN Community 和 Professional 版本的主要差异
    本文详细解析了 DotNetNuke (DNN) 的两种主要版本:Community 和 Professional。通过对比两者的功能和附加组件,帮助用户选择最适合其需求的版本。 ... [详细]
  • 本文详细记录了在基于Debian的Deepin 20操作系统上安装MySQL 5.7的具体步骤,包括软件包的选择、依赖项的处理及远程访问权限的配置。 ... [详细]
  • 优化ListView性能
    本文深入探讨了如何通过多种技术手段优化ListView的性能,包括视图复用、ViewHolder模式、分批加载数据、图片优化及内存管理等。这些方法能够显著提升应用的响应速度和用户体验。 ... [详细]
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • PyCharm下载与安装指南
    本文详细介绍如何从官方渠道下载并安装PyCharm集成开发环境(IDE),涵盖Windows、macOS和Linux系统,同时提供详细的安装步骤及配置建议。 ... [详细]
  • 本文详细介绍了如何解决Uploadify插件在Internet Explorer(IE)9和10版本中遇到的点击失效及JQuery运行时错误问题。通过修改相关JavaScript代码,确保上传功能在不同浏览器环境中的一致性和稳定性。 ... [详细]
  • 本文探讨了Hive中内部表和外部表的区别及其在HDFS上的路径映射,详细解释了两者的创建、加载及删除操作,并提供了查看表详细信息的方法。通过对比这两种表类型,帮助读者理解如何更好地管理和保护数据。 ... [详细]
  • CentOS7源码编译安装MySQL5.6
    2019独角兽企业重金招聘Python工程师标准一、先在cmake官网下个最新的cmake源码包cmake官网:https:www.cmake.org如此时最新 ... [详细]
  • 本文介绍了如何使用JQuery实现省市二级联动和表单验证。首先,通过change事件监听用户选择的省份,并动态加载对应的城市列表。其次,详细讲解了使用Validation插件进行表单验证的方法,包括内置规则、自定义规则及实时验证功能。 ... [详细]
  • 本文探讨了 Objective-C 中的一些重要语法特性,包括 goto 语句、块(block)的使用、访问修饰符以及属性管理等。通过实例代码和详细解释,帮助开发者更好地理解和应用这些特性。 ... [详细]
author-avatar
妮妮快乐1_514
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有