Open aidanas opened 3 years ago
I hope to test this in the near future, adding a bug label for now. Thanks.
Anyone found a solution to this? Or maybe a workaround? I'm getting the same issue doing:
ionic cordova build browser
after adding this version of the plugin
Anything new regarding this issue? I would really love to us this plugin for electron
I also just came across this problem. Effectively you can't build for Electron that doesn't use sqlite and for iOS that does use sqlite plugin on the same machine. Any workaround available? Thanks
I have a workaround but it is not pretty.
1) Remove the cordova-sqlite-storage plugin % cordova plugin remove cordova-sqlite-storage
2) Edit the following files and remove all JSON objects that have a pluginId: "cordova-sqlite-storage"
./platforms/electron/www/cordova_plugins.js ./platforms/electron/electron.json ./platforms/electron/platform_www/cordova_plugins.js
eg: { "file": "plugins/cordova-sqlite-storage/src/browser/SQLiteProxy.js", "id": "cordova-sqlite-storage.SQLiteProxy", "pluginId": "cordova-sqlite-storage", "runs": true }
These JSON objects in these files should be removed by the removal of the plugin. That is another bug I guess. It may be possible to only have to edit 1 of these files, but I don't know the relationship between these files.
3) Build the Electron platform % cordova build electron
If you want to build another platform that uses cordova-sqlite-storage plugin, then you will need to add the plugin again
Hi the problem is the missing sql-asm-memory-growth.js file which is present in the plugins/cordova-sqlite-storage/node_modules/cordova-sqlite-storage-dependencies but when i open the electron Application and search for this path its not there.
Then i realized for some reason electron-builder does not copy directories named "node_modules" into my application which can be manged in seperate electon applcations by just giving a configration called
"build": {
"includeSubNodeModules": true
}
but not albe to do that in cordova application so only thing left for us is to use cordova hooks to do two things
Please use the below hook as refernce and do the job in config.xml inside the <platform name="electron">
add <hook src="buildhooks/update-sql-storage.js" type="after_prepare" />
so it looks something like
<platform name="electron">
<hook src="hooks/after_prepare.js" type="after_prepare" />
<preference name="ElectronSettingsFilePath" value="res/electron/settings.json" />
</platform>
Create a file called after_prepare.js inside hooks folder and paste the below code
const fs = require('fs');
const path = require('path');
module.exports = function (ctx) {
const rootDir = ctx.opts.projectRoot;
const electronDir = path.join(rootDir, 'platforms', 'electron');
const platformWwwDir = path.join(electronDir, 'platform_www');
const filesToModify = [
path.join(electronDir, 'electron.json'), // Corrected path for electron.json
path.join(platformWwwDir, 'cordova_plugins.js'),
];
const searchAndReplace = (filePath, searchValue, replaceValue) => {
try {
if (fs.existsSync(filePath)) {
let fileContent = fs.readFileSync(filePath, 'utf8');
if (fileContent.includes(searchValue)) {
fileContent = fileContent.replace(searchValue, replaceValue);
fs.writeFileSync(filePath, fileContent, 'utf8');
console.log(`Updated ${filePath}`);
}
} else {
console.warn(`File ${filePath} does not exist.`);
}
} catch (err) {
console.error(`Error updating file ${filePath}:`, err);
}
};
const copyFile = (srcPath, destPath) => {
try {
const destDir = path.dirname(destPath);
if (!fs.existsSync(destDir)) {
fs.mkdirSync(destDir, { recursive: true });
}
fs.copyFileSync(srcPath, destPath);
console.log(`Copied ${srcPath} to ${destPath}`);
} catch (err) {
console.error(`Error copying file from ${srcPath} to ${destPath}:`, err);
}
};
const searchValue = 'plugins/cordova-sqlite-storage/node_modules/cordova-sqlite-storage-dependencies/sql-asm-memory-growth.js';
const replaceValue = 'plugins/cordova-sqlite-storage-dependencies/sql-asm-memory-growth.js';
// Search and replace in files
filesToModify.forEach((filePath) => {
searchAndReplace(filePath, searchValue, replaceValue);
});
// Copy the file
const srcFilePath = path.join(
platformWwwDir,
'plugins',
'cordova-sqlite-storage',
'node_modules',
'cordova-sqlite-storage-dependencies',
'sql-asm-memory-growth.js',
);
const destFilePath = path.join(
platformWwwDir,
'plugins',
'cordova-sqlite-storage-dependencies',
'sql-asm-memory-growth.js',
);
if (fs.existsSync(srcFilePath)) {
copyFile(srcFilePath, destFilePath);
} else {
console.error(`Source file ${srcFilePath} does not exist.`);
}
};
Thanks for a better workaround. I have implemented the hook, albeit in a different scripting language and can confirm it works.
If the plugin is added to project it breaks electron builds with the following errors printed to console:
I understand that the plugin does not support electron platform but it used to not actively break it either. The issue can be recreated using basic "HelloWorld". Steps to recreate:
cordova create helloworld com.example.hello HelloWorld
cordova platform add electron@2.0.0
cordova plugin add cordova-sqlite-storage
cordova build electron --debug
./platforms/electron/build/
This appears to have been introduced in plugin version
5.1.0
as it still works fine on5.0.0
Those are additional version comparisons: