SQLITE_CANTOPEN: unable to open database file electronjs - javascript

I am facing the sqlite db issue in production mode.
Its working fine on using npm start (on normally run) but not working when i try to create release file for linux using electron-builder build --linux
my package.json file is as follows
{
"name": "test",
"version": "1.0.0",
"description": "test",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "electron .",
"dist": "electron-builder"
},
"author": "",
"license": "ISC",
"devDependencies": {
"electron": "^13.1.0",
"electron-packager": "^15.2.0"
},
"build": {
"appId": "pkg.dmo.com",
"productName": "sample",
"copyright": "Copyright",
"mac": {
"target": [
"zip"
],
"publish": [
"github"
]
},
"win": {
"target": [
"nsis"
]
},
"linux": {
"target": [
"AppImage",
"tar.gz"
]
},
"dmg": {
"icon": "build/icon.icns"
}
},
"dependencies": {
"jquery": "^3.6.0",
"sqlite3": "^5.0.2"
}
}
and my sqlite code is as follows:
let $ = (jQuery = require("jquery"));
const sqlite3 = require("sqlite3").verbose();
const path = require('path')
const dbPath = path.join(__dirname, 'testdb.db');
$( document ).ready(function() {
let db = new sqlite3.Database(
dbPath,
sqlite3.OPEN_READWRITE,
(err) => {
if (err) {
console.error(err.message);
}
}
);
db.each("SELECT * FROM Mouse", [], function (err, row) {
console.log("helli");
if (err) {
console.log(err);
return console.error(err.message);
}
console.log("mouse row is =>", row);
});
});
i have tried
var db = new sqlite3.Database( path.resolve(__dirname, 'testdb.db') );
and
var db = new sqlite3.Database( path.join(__dirname,
'testdb.db').replace('/app.asar', '') );
still getting same error in exe but working on local(when npm start)

Related

Why isn't electron builder returning a .pkg file?

so I'll keep it short. I've been following this tutorial: https://www.techandstartup.org/tutorials/release-electron-app-on-mac-app-store
However as you'll see we need a pkg file to be uploaded to Transporter for App Store Connect. But when I run 'electron-builder' command I only get an 'Application' .I don't get any .dmg files or .pkg file. This is how my .plis looks like `
{
"name": "APPP",
"productName": "APPP",
"version": "1.0.0",
"description": "My Electron application description",
"main": "src/index.js",
"scripts": {
"start": "electron .",
"dist": "electron-builder --mac"
},
"keywords": [],
"author": {
"name": "ME",
"email": "ME#gmail.com"
},
"license": "MIT",
"devDependencies": {
"electron": "^17.1.2",
"electron-builder": "^22.14.13",
"electron-packager": "^15.5.1"
},
"build": {
"appId": "com.APP",
"productName": "Frost",
"buildVersion": "1.0.0",
"copyright": "Copyright © 2022 Developer or Company Name",
"mac": {
"category": "public.app-category.Productivity",
"icon": "/Users/alex/frost/src/icon.icns",
"target": "dmg",
"hardenedRuntime": false,
"entitlements": "/Users/alex/frost/entitlements.mas.plist",
"entitlementsInherit": "/Users/alex/frost/entitlements.mas.inherit.plist",
"provisioningProfile": "/Users/alex/frost/AppleDevelopment.provisionprofile",
"type": "development"
}
},
"dependencies": {
"electron-squirrel-startup": "^1.0.0"
}
}
`

Electron application in production throw: error Command failed: node index.js but in development works fine

Have you ever had this issue:
I was working on my app in development, and everything works fine, but when I created the executable and try to click on my button throw this error:
This the code that is executed when I press my button:
const { exec } = require("child_process");
let myBtn = document.getElementById('my-btn');
myBtn.addEventListener('click', (e) => {
e.preventDefault();
exec("node index.js", (error, data, getter) => {
if(error){
console.log("error",error.message);
return;
}
if(getter){
console.log("data",data);
return;
}
console.log("data",data);
});
});
This the error:
Not recognize the module node and my file index.js
error Command failed: node index.js
internal/modules/cjs/loader.js:1068
throw err;
^
Error: Cannot find module '/home/myUser/index.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1065:15)
at Function.Module._load (internal/modules/cjs/loader.js:911:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
This is my package.json
{
"name": "app",
"version": "1.0.0",
"description": "description",
"main": "main.js",
"dependencies": {
"electron-squirrel-startup": "^1.0.0",
"puppeteer": "^9.0.0"
},
"devDependencies": {
"#electron-forge/cli": "^6.0.0-beta.54",
"#electron-forge/maker-deb": "^6.0.0-beta.54",
"#electron-forge/maker-rpm": "^6.0.0-beta.54",
"#electron-forge/maker-squirrel": "^6.0.0-beta.54",
"#electron-forge/maker-zip": "^6.0.0-beta.54",
"electron": "^12.0.5"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "electron-forge start",
"package": "electron-forge package",
"make": "electron-forge make"
},
"repository": {
"type": "git",
"url": ""
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": ""
},
"homepage": "",
"config": {
"forge": {
"packagerConfig": {},
"makers": [
{
"name": "#electron-forge/maker-squirrel",
"config": {
"name": "app"
}
},
{
"name": "#electron-forge/maker-zip",
"platforms": [
"darwin"
]
},
{
"name": "#electron-forge/maker-deb",
"config": {}
},
{
"name": "#electron-forge/maker-rpm",
"config": {}
}
]
}
}
}

Data path "" should NOT have additional properties(scripts) when adding external js to a non-application project

Already updated my node and angular. When doing ng build I get error:
Schema validation failed with the following errors:
Data path "" should NOT have additional properties(scripts).
generated project via:
ng n my-proj **-create-application=false**
angular.json :
{
"$schema": "./node_modules/#angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"my-proj-lib": {
"projectType": "library",
"root": "projects/my-proj-lib",
"sourceRoot": "projects/my-proj-lib/src",
"prefix": "lib",
"architect": {
"build": {
"builder": "#angular-devkit/build-ng-packagr:build",
"options": {
"tsConfig": "projects/my-proj-lib/tsconfig.lib.json",
"scripts": [
"other-libs/jqBootstrapValidation.js"
],
"project": "projects/my-proj-lib/ng-package.json"
}
},
"test": {
...
},
"lint": {
...
}
}
}},
"defaultProject": "my-proj-lib"
}

Include a folder and the files inside it to electron build using electron-builder?

I have a few JSON files inside a directory named data in the working directory of my Electron project. I succeeded in building the app using electron-build with the following configuration (package.json).
{
"name": "My App",
"version": "0.0.9",
"description": "TEST DESC",
"main": "main.js",
"scripts": {
"start": "electron .",
"pack": "build --dir",
"dist": "build"
}
"author": "Test",
"license": "CC0-1.0",
"build": {
"appId": "test.tester.test",
"directories": {
"app": ""
},
"extraFiles": [
"data"
],
"dmg": {
"contents": [
{
"x": 110,
"y": 150
},
{
"x": 240,
"y": 150,
"type": "link",
"path": "/Applications"
}
]
},
"win": {
"target": "squirrel",
"icon": "build/icon.ico"
}
},
"devDependencies": {
"electron": "~1.7.8",
"electron-builder": "^20.11.1"
},
"dependencies": {
"electron-settings": "^3.1.4",
"jquery": "^3.3.1",
"leveldown": "^3.0.0",
"mkdirp": "^0.5.1",
"shelljs": "^0.8.1"
}
}
I suppose the data directory is not getting added to the build file. Because I am using the files inside of the data directory to render the views in the app, which is not working in the built app. Please suggest a solution.
I am using these JSON files inside the app like this:
fs.readFile('./data/userdata.json', 'utf8', function readFileCallback(err, data) {
if(data == '') { data = '[]'; }
var users = JSON.parse(data);
//Render Code
});
"build": {
"extraResources": [
{
"from": "data",
"to": "data"
}
]
}
After add like this then Electron-builder will copy the data folder to app's resource/data after packing the app. So that you can read the files with
this.
const dataPath =
process.env.NODE_ENV === 'development'
? path.join(__dirname, '../../data')
: path.join(process.resourcesPath, 'data');
fs.readFile(path.join(dataPath,'userdata.json', 'utf8', function readFileCallback(err, data) {
if(data == '') { data = '[]'; }
var users = JSON.parse(data);
//Render Code
});

request.ref is not a function

I ran the node code on this site https://firebase.googleblog.com/2016/08/sending-notifications-between-android.html by using:
node app
I get the following error:
TypeError: request.ref is not a function.
which corresponds to the following line:
sendNotificationToUser("username","new msg",function() {request.ref().remove();} );
This is my package.json file:
{
"name": "myApp",
"version": "1.0.1",
"description": "listen for addition of msgs",
"main": "app.js",
"scripts": {
"start": "node app.js",
"monitor": "nodemon app.js",
"deploy": "gcloud app deploy"
},
"author": "my name",
"engines": {
"node": "~4.2"
},
"license": "ISC",
"dependencies": {
"firebase": "^3.2.1",
"request": "^2.74.0"
}
}
There are indeed some typos in the code. The actual version I run with uses this to remove the messages that have been sent:
requestSnapshot.ref.remove();
The entire listenForNotificationRequests method (in case I made any other edit mistakes while porting to the blog):
function listenForNotificationRequests() {
var requests = ref.child('notificationRequests');
requests.on('child_added', function(requestSnapshot) {
var request = requestSnapshot.val();
sendNotificationToUser(
request.username,
request.message,
function() {
requestSnapshot.ref.remove();
}
);
}, function(error) {
console.error(error);
});
};

Categories

Resources