问题描述
在我的 Electron-React-Typescript-Webpack 应用程序中,我安装了这些包:
"devDependencies":
"electron": "^12.0.0","typescript": "^4.1.5","@types/node": "^14.14.28","@types/pouchdb-core":` "^7.0.6","@types/pouchdb-find": "^6.3.6","@types/pouchdb-replication": "^6.4.2","webpack": "^5.23.0"
"dependencies":
"pouchdb": "^7.2.2","pouchdb-adapter-http": "^7.2.2","pouchdb-adapter-idb": "^7.2.2","pouchdb-adapter-leveldb": "^7.2.2","pouchdb-adapter-localstorage": "^7.2.2","pouchdb-adapter-memory": "^7.2.2","pouchdb-adapter-websql": "^7.0.0","pouchdb-all-dbs": "^1.1.1","pouchdb-core": "^7.2.2","pouchdb-debug": "^7.2.1","pouchdb-find": "^7.2.2","pouchdb-replication": "^7.2.2","pouchdb-selector-core": "^7.2.2","pouchdb-utils": "^7.2.2","rxdb": "file:rxdb-local.tgz"
我创建了这个 /src/infopiecesDb.js
文件
const {
createRxDatabase,addRxPlugin
} = require('rxdb');
addRxPlugin(require('pouchdb-adapter-http'));
const infopieceSchema = {
title: 'infopiece schema',description: 'describes a simple infopiece',version: 0,type: 'object',properties: {
id: {
type: 'number',},doc_path: {
type: 'string'
},date: {
type: 'string'
},title: {
type: 'string',primary: true
},body: {
type: 'string,'
}
},required: ['body']
};
let _getDatabase; // cached
function getDatabase(name,adapter) {
if (!_getDatabase) _getDatabase = createDatabase(name,adapter);
return _getDatabase;
}
async function createDatabase(name,adapter) {
const db = await createRxDatabase({
name,adapter,password: 'myLongAndStupidPassword'
});
console.log('creating infopieces ..');
await db.collection({
name: 'infopieces',schema: infopieceSchema
});
return db;
}
module.exports = {
getDatabase
};
在 /src/main/main.ts
中,我添加了以下几行:
import infopiecesDb from '../rxdb/infopiecesDb';
import { addRxPlugin } from 'rxdb';
addRxPlugin(require('rxdb/plugins/server'));
addRxPlugin(require('pouchdb-adapter-memory'));
app.on('ready',async () => {
createMainWindow();
const db = await infopiecesDb.getDatabase(
'infopiecesdb','memory'
);
// spawn a server
console.log('start server');
await db.server({
path: '/db',port: 10102,cors: true
});
console.log('started server');
})
正在执行,应用程序打开,但我收到此消息:
yarn start electron --trace-warnings ...
yarn run v1.22.5
$ yarn run build && electron ./dist/main/main.js electron --trace-warnings ...
$ npx webpack --config ./webpack.config.js
asset main.js 3.3 MiB [compared for emit] (name: main)
orphan modules 263 KiB [orphan] 138 modules
runtime modules 1.06 KiB 6 modules
modules by path ./node_modules/ 2.54 MiB
javascript modules 2.17 MiB 382 modules
json modules 376 KiB
modules by path ./node_modules/iconv-lite/encodings/tables/*.json 86.7 KiB 8 modules
./node_modules/statuses/codes.json 1.54 KiB [built] [code generated]
./node_modules/send/node_modules/mime/types.json 30.8 KiB [built] [code generated]
./node_modules/psl/data/rules.json 117 KiB [built] [code generated]
./node_modules/mime-db/db.json 139 KiB [built] [code generated]
modules by path ./src/ 10.9 KiB
./src/main/main.ts 7.18 KiB [built] [code generated]
./src/main/menu/menuTemplateInfobasket.js 2.54 KiB [built] [code generated]
./src/rxdb/infopiecesDb.js 1.17 KiB [built] [code generated]
20 modules
WARNING in ./node_modules/express/lib/view.js 81:13-25
Critical dependency: the request of a dependency is an expression
@ ./node_modules/express/lib/application.js 22:11-28
@ ./node_modules/express/lib/express.js 18:12-36
@ ./node_modules/express/index.js 11:0-41
@ ./node_modules/rxdb/dist/es/plugins/server.js 3:0-30 126:12-19
@ ./src/main/main.ts 36:19-49
WARNING in ./node_modules/rxdb/dist/es/plugins/server.js 17:19-45
Module not found: Error: Can't resolve 'express-pouchdb' in '/home/marco/webMatters/electronMatters/Raphy-Template
/node_modules/rxdb/dist/es/plugins'
@ ./src/main/main.ts 36:19-49
2 warnings have detailed information that is not shown.
Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.
webpack 5.31.0 compiled with 2 warnings in 11723 ms
Since version 8.4.0 the module 'express-pouchdb' is not longer delivered with RxDB.
You can install it with 'npm install express-pouchdb'
creating infopieces ..
start server
(node:16189) UnhandledPromiseRejectionWarning: TypeError: ExpresspouchDB is not a function
at RxDatabaseBase.spawnServer [as server] (/home/marco/webMatters/electronMatters/Raphy-Template/node_modules
/rxdb/dist/lib/plugins/server.js:169:18)
at App.<anonymous> (/home/marco/webMatters/electronMatters/Raphy-Template/dist/main/main.js:46:14)
at processticksAndRejections (internal/process/task_queues.js:93:5)
(Use `electron --trace-warnings ...` to show where the warning was created)
(node:16189) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing
inside of an async function without a catch block,or by rejecting a promise which was not handled with .catch(). To terminate
the node process on unhandled promise rejection,use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org
/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:16189) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future,promise rejections
that are not handled will terminate the Node.js process with a non-zero exit code.
mainWindow loaded
如果我用 yarn add express-pouchdb@latest
安装 express-pouchdb:
├─ express-pouchdb@4.2.0
当我启动应用程序时出现此错误:
(base) marco@pc01:~/webMatters/electronMatters/Raphy-Template$ yarn start
yarn run v1.22.5
$ yarn run build && electron ./dist/main/main.js
$ npx webpack --config ./webpack.config.js
asset main.js 3.94 MiB [emitted] (name: main)
orphan modules 263 KiB [orphan] 138 modules
runtime modules 1.16 KiB 7 modules
modules by path ./node_modules/ 3.05 MiB
javascript modules 2.69 MiB
cacheable modules 2.68 MiB 509 modules
./node_modules/express-pouchdb/lib/ sync ^\.\/.*$ 2.51 KiB [built] [code generated]
./node_modules/express/lib/ sync 160 bytes [built] [code generated]
json modules 376 KiB
modules by path ./node_modules/iconv-lite/encodings/tables/*.json 86.7 KiB 8 modules
4 modules
modules by path ./src/ 10.9 KiB
./src/main/main.ts 7.18 KiB [built] [code generated]
./src/main/menu/menuTemplateInfobasket.js 2.54 KiB [built] [code generated]
./src/rxdb/infopiecesDb.js 1.17 KiB [built] [code generated]
22 modules
WARNING in ./node_modules/express/lib/view.js 81:13-25
Critical dependency: the request of a dependency is an expression
@ ./node_modules/express/lib/application.js 22:11-28
@ ./node_modules/express/lib/express.js 18:12-36
@ ./node_modules/express/index.js 11:0-41
@ ./node_modules/rxdb/dist/es/plugins/server.js 3:0-30 126:12-19
@ ./src/main/main.ts 36:19-49
1 warning has detailed information that is not shown.
Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.
ERROR in ./node_modules/express-pouchdb/lib/routes/root.js 3:13-37
Module not found: Error: Can't resolve '../../package' in '/home/marco/webMatters/electronMatters/Raphy-Template
/node_modules/express-pouchdb/lib/routes'
resolve '../../package' in '/home/marco/webMatters/electronMatters/Raphy-Template/node_modules/express-pouchdb/lib/routes'
using description file: /home/marco/webMatters/electronMatters/Raphy-Template/node_modules/express-pouchdb
/package.json (relative path: ./lib/routes)
using description file: /home/marco/webMatters/electronMatters/Raphy-Template/node_modules/express-pouchdb
/package.json (relative path: ./package)
no extension
/home/marco/webMatters/electronMatters/Raphy-Template/node_modules/express-pouchdb/package doesn't exist
.jsx
/home/marco/webMatters/electronMatters/Raphy-Template/node_modules/express-pouchdb/package.jsx doesn't exist
.js
/home/marco/webMatters/electronMatters/Raphy-Template/node_modules/express-pouchdb/package.js doesn't exist
ts
/home/marco/webMatters/electronMatters/Raphy-Template/node_modules/express-pouchdb/packagets doesn't exist
as directory
/home/marco/webMatters/electronMatters/Raphy-Template/node_modules/express-pouchdb/package doesn't exist
@ ./node_modules/express-pouchdb/lib/ sync ^\.\/.*$ ./routes/root.js ./routes/root
@ ./node_modules/express-pouchdb/lib/index.js 238:6-26
@ ./node_modules/rxdb/dist/es/plugins/server.js 17:19-45
@ ./src/main/main.ts 36:19-49
ERROR in ./node_modules/pouchdb-fauxton/www/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
> <!--
| // Licensed under the Apache License,Version 2.0 (the "License");
you may not
| // use this file except in compliance with the License. You may
obtain a copy of
@ ./node_modules/express-pouchdb/lib/routes/fauxton.js 7:32-66
@ ./node_modules/express-pouchdb/lib/ sync ^\.\/.*$ ./routes
/fauxton.js ./routes/fauxton
@ ./node_modules/express-pouchdb/lib/index.js 238:6-26
@ ./node_modules/rxdb/dist/es/plugins/server.js 17:19-45
@ ./src/main/main.ts 36:19-49
webpack 5.31.0 compiled with 2 errors and 1 warning in 11729 ms
应用程序打不开....
O.S.: Ubuntu 18.04.4 Desktop
node: v14.5.0
nvm: 0.34.0
我在这里发现了一个类似的问题:express-pouchdb relative module was not found 但那里给出的指示并没有解决我的问题
如何解决问题?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)