简体   繁体   中英

How to solve the problem with sqlite in cordova?

I'm moving the electron project to cordova. To work with sqlite I use NPM plugin sqlite-sync. In electron it worked perfectly. After porting the sources and installing the dependencies, I see an error when starting the project.

ERROR in ./node_modules/sql.js/js/sql.js
Module not found: Error: Can't resolve 'fs' in 'D:\PROJECTS\PRODUCTIONS\MOBILE\\node_modules\sql.js\js'
 @ ./node_modules/sql.js/js/sql.js 3:1275-1288 3:170484-170497
 @ ./node_modules/sqlite-sync/sqlite.js
 @ ./src/store/index.js
 @ ./src/main.js
 @ multi ./build/dev-client babel-polyfill ./src/main.js

how fix problem? win platform

Electron and Cordova are not the same, Electron implements the NodeJS API while Cordova uses its own API. If you want to use SqlLite in cordova you are going to have to rip out the parts that use NodeJS (if you see the word 'require' it is probably a node import -- in fact to make life easier on yourself use ES6 imports with WebPack or Browserify so that you know which code to rip out). You may be able to use a lot of node_modules with a modern build system but it is going to be a fair bit of work to move from Electron to Cordova. If you want to use SQLite, the SQLite Cordova Plugin is probably the easiest way to do this, but it is going to look a little different from the NodeJs Sqlite API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM