我正在尝试在电子应用程序中使用node-sqlite3,但在应用程序窗口中,我在 chrome 控制台中收到以下错误:
Uncaught TypeError: Cannot read property '_handle' of undefined
at file:///[...]/assets/js/bundle.js:38727:15
at Array.forEach (native)
at module.exports (file:///[...]/assets/js/bundle.js:38726:36)
at Object.<anonymous> (file:///[...]/assets/js/bundle.js:34699:1)
at Object.147._process (file:///[...]/assets/js/bundle.js:34999:4)
at s (file:///[...]/assets/js/bundle.js:1:254)
at file:///[...]/assets/js/bundle.js:1:305
at Object.<anonymous> (file:///[...]/assets/js/bundle.js:32065:11)
at Object.141.../package.json (file:///[...]/assets/js/bundle.js:32246:4)
at s (file:///[...]/assets/js/bundle.js:1:254)
错误发生在第3行file:///[...]/assets/js/node_modules/sqlite3/node_modules/set-blocking/index.js
(这个文件是自动生成删除的,不是我写的):
module.exports = function (blocking) {
[process.stdout, process.stderr].forEach(function (stream) {
if (stream._handle && stream.isTTY && typeof stream._handle.setBlocking === 'function') {
stream._handle.setBlocking(blocking)
}
})
}
这仅在渲染器进程内部使用时才会发生const sqlite3 = require('sqlite3')
(例如在 React 组件中)。require('sqlite3')
在主电子过程中使用时没有任何问题(数据库调用有效)。
此示例应用程序显示可以在渲染器进程中使用 sqlite 模块。我不明白为什么它在我的情况下不起作用。
我的package.json
:
{
...,
"scripts": {
"postinstall": "install-app-deps",
"start": "electron .",
"watch": "watchify app/app.js -t babelify -o assets/js/bundle.js --debug --verbose",
"watch-style": "sass -r sass-globbing --watch style/application.scss:assets/css/bundle.css"
},
"devDependencies": {
"babel-preset-stage-2": "^6.24.1",
"electron-builder": "^19.49.4"
},
"dependencies": {
"babel": "^6.23.0",
"babel-core": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babelify": "^8.0.0",
"browserify": "^14.5.0",
"electron": "^1.7.10",
"electron-reload": "^1.2.2",
"electron-window-state": "^4.1.1",
"react": "^16.2.0",
"sqlite3": "^3.1.13",
"watchify": "^3.9.0",
...
}
}
我使用:节点 7.9.0,铬 58.0.3029.110,电子 1.7.10。
我在这里在 github 上创建了一个问题。