I want to connect to my database which is sqlite3. This is work fine on localhost and fail when I deployed to zeit.co with ERROR:
Error: SQLITE_CANTOPEN: unable to open database
As I understand, this issue is because we cannot get right path to database file. I have tried some solutions but still failed. Plz help!!!
Here is error on zeit.co log:
2020-02-13T07:50:40.031Z 4d5a9aed-ae26-4a09-903a-72aa08ca5140 ERROR Unhandled Promise Rejection {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"Error: SQLITE_CANTOPEN: unable to open database file","reason":{"errorType":"Error","errorMessage":"SQLITE_CANTOPEN: unable to open database file","code":"SQLITE_CANTOPEN","errno":14,"stack":["Error: SQLITE_CANTOPEN: unable to open database file"]},"promise":{"isFulfilled":false,"isRejected":true,"rejectionReason":{"errorType":"Error","errorMessage":"SQLITE_CANTOPEN: unable to open database file","code":"SQLITE_CANTOPEN","errno":14,"stack":["Error: SQLITE_CANTOPEN: unable to open database file"]}},"stack":["Runtime.UnhandledPromiseRejection: Error: SQLITE_CANTOPEN: unable to open database file"," at process. (/var/runtime/index.js:35:15)"," at process.emit (events.js:228:7)"," at eventToObjectGenerator.promiseCreated (/var/task/node_modules/bluebird/js/release/debuggability.js:258:33)"," at activeFireEvent (/var/task/node_modules/bluebird/js/release/debuggability.js:301:44)"," at fireRejectionEvent (/var/task/node_modules/bluebird/js/release/debuggability.js:703:14)"," at Promise._notifyUnhandledRejection (/var/task/node_modules/bluebird/js/release/debuggability.js:90:9)"," at Timeout.unhandledRejectionCheck [as _onTimeout] (/var/task/node_modules/bluebird/js/release/debuggability.js:39:25)"," at listOnTimeout (internal/timers.js:531:17)"," at processTimers (internal/timers.js:475:7)"]} Unknown application error occurred
Here is the code that I connect to sqlite
const fs = require('fs');
const path = require('path');
const DBSOURCE = path.join(__dirname, 'mydb.sqlite');
const knex = require('knex')({
client: 'sqlite3',
connection: {
filename: DBSOURCE
}
});
Note:
- I have tried
const DBSOURCE = 'mydb.sqlite'
; - I have tried
const DBSOURCE = path.resolve(__dirname, 'mydb.sqlite');