angular - 在 Angular + Electron 应用程序中使用 sqlite3 : Critical dependency: the request of a dependency is an expression

标签 angular sqlite webpack electron node-sqlite3

在我的Angular + Electron app我正在尝试安装一些 sqlite 库,以便从 sqlite 数据库文件中读取内容。

我已经安装了sqlite3使用:

npm install sqlite3
npm install --save-dev @types/sqlite3

我尝试用它来做:

import * as sqlite from 'sqlite3';

// ...

const myDb = new sqlite.Database('/path/to/file.sqlite');

但是,当应用程序构建时,它会失败并显示:

WARNING in ./node_modules/sqlite3/lib/sqlite3.js 4:14-35 Critical dependency: the request of a dependency is an expression

WARNING in ./node_modules/node-pre-gyp/lib/pre-binding.js 20:22-48 Critical dependency: the request of a dependency is an expression

WARNING in ./node_modules/node-pre-gyp/lib/util/versioning.js 17:20-67 Critical dependency: the request of a dependency is an expression

WARNING in ../node_modules/npm/lib/npm.js 124:16-56 Critical dependency: the request of a dependency is an expression

WARNING in ../node_modules/npm/lib/npm.js 235:10-25 Critical dependency: the request of a dependency is an expression

WARNING in ../node_modules/npm/node_modules/encoding/lib/iconv-loader.js 9:12-34 Critical dependency: the request of a dependency is an expression

WARNING in ./node_modules/node-pre-gyp/lib/util/compile.js Module not found: Error: Can't resolve 'node-gyp' in '/home/shin/sources/Keira3/node_modules/node-pre-gyp/lib/util'

WARNING in ./node_modules/node-pre-gyp/lib/util/nw-pre-gyp/index.html 1:0 Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders

| |

./node_modules/node-pre-gyp/lib/info.js 中出现错误 找不到模块: 错误:无法解析“aws-sdk” '/home/shin/sources/Keira3/node_modules/node-pre-gyp/lib' 中的错误 ./node_modules/node-pre-gyp/lib/publish.js 找不到模块:错误: 无法解析“aws-sdk” '/home/shin/sources/Keira3/node_modules/node-pre-gyp/lib' 中的错误 ./node_modules/node-pre-gyp/lib/unpublish.js 找不到模块:错误: 无法解析“aws-sdk” '/home/shin/sources/Keira3/node_modules/node-pre-gyp/lib' 中的错误 ../node_modules/npm/bin/npm-cli.js 1:0 模块解析失败:意外 字符 '#' (1:0) 您可能需要适当的加载程序来处理此问题 文件类型,当前没有配置加载程序来处理此文件。 请参阅https://webpack.js.org/concepts#loaders

!/usr/bin/env node | ;(function () { // wrapper in case we're in module_context mode | // windows: running "npm blah" in this folder

will invoke WSH, not node.

this thread这个问题的解决方案已经发布,它是将以下内容添加到 webpack 配置文件中:

externals: { 'sqlite3':'commonjs sqlite3', }

但是我不清楚在 Angular 应用程序中的何处添加此类配置。

最佳答案

我使用 Custom webpack builders (angular-builders) 解决了我的问题.

Allow customizing build configuration without ejecting webpack configuration (ng eject)

安装后,我现在可以在添加的位置指定自定义 Webpack 配置:

module.exports = {
    externals: {
        'sqlite3':'commonjs sqlite3'
    }
};

我还必须运行node postinstall && electro-builder install-app-dep才能使其正常工作。

关于angular - 在 Angular + Electron 应用程序中使用 sqlite3 : Critical dependency: the request of a dependency is an expression,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60363339/

相关文章:

reactjs - Jest 与 webpack 提供插件

jquery - angular 2 wepack元素添加jquery(Bootstrap的JavaScript需要jQuery)

angular - 我在 angular 2 cli 中的 webpack 配置文件在哪里?

node.js - extraHeaders 未附加到请愿书上

Angular 2 : Dynamically add component after n-th child

javascript - 如何使用 Angular 2 在 *ngFor 列表中显示被点击的元素隐藏其他元素

Android SQLite 列值相对增加

python - 将超过一亿行插入 SQLite 数据库的最佳方法是什么?

AngularJS 2 ZoneAwarePromise 而不是 bool 值

php - PDO 从一个数据库插入到另一个数据库