gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 12:25:45 25 4
gpt4 key购买 nike

在我的 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 && electron-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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com