Pkg: SQLITE_CANTOPEN: unable to open database file

Created on 12 Dec 2017  路  11Comments  路  Source: vercel/pkg

Node v8.3.0
NPM v5.3.0
[email protected]

package.json:

```{
"name": "cca",
"version": "1.0.0",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"inquirer": "^4.0.1",
"lowdb": "^1.0.0",
"nexe": "^2.0.0-rc.22",
"pkg": "^4.3.0-beta.1",
"request": "^2.83.0",
"request-promise-native": "^1.0.5",
"sqlite3": "^3.1.13"
},
"description": "",
"bin": "./main.js",
"pkg": {
"assets": "./main.db"
}
}

Im using sqlite3 package for node, trying to access my db file:

function connectToDB() {
return new Promise(function(resolve, reject) {
var db_path = path.resolve(__dirname, 'main.db');
console.log(db_path);
test = fs.statSync(db_path);
console.log(test);
db = new sqlite3.Database(db_path, (err) => {
if(err) {
reject('Error: ' + err);
}
else {
resolve('Conected to DB');
}
});
})
}

I know the file is there as it can be reached by fs, here is the output from console.logs:

/snapshot/dist/main.db
{ mode: 33279,
size: 8192,
blksize: 4096,
blocks: 0,
dev: 0,
gid: 20,
ino: 0,
nlink: 0,
rdev: 0,
uid: 500,
atime: 2017-12-12T21:17:30.860Z,
mtime: 2017-12-12T21:17:29.156Z,
ctime: 2017-12-12T21:17:29.156Z,
birthtime: 2017-12-12T21:17:29.156Z,
atimeMs: 1513113450860,
mtimeMs: 1513113449156,
ctimeMs: 1513113449156,
birthtimeMs: 1513113449156,
isFile: [Function],
isDirectory: [Function],
isSymbolicLink: [Function],
isFIFO: [Function] }
```

And the sqlite3 error:

Error: SQLITE_CANTOPEN: unable to open database file

Most helpful comment

I had this issue also and resolved it by creating directory "database" in my project directory.

All 11 comments

@colinmcparland how did you resolve the issue

edit: fixed - my issue was that i used path.resolve(__dirname, filename) to locate my db files

meet the same issue, any one can help?

had this for months, any solution?

I'm also having this same issue. Is there a reason why it's closed?

Tried with and without path.resolve() (and path.normalize() etc.)... all get same same issue:
file exists
but sqlite via nodejs gets the SQLITE_CANTOPEN error as described here.

I've set READONLY on the db, since I'm pretty sure it won't be writable since code isn't in /tmp and underlying Lambda isn't writable.

Could very will be missing something, but tried a bunch.

check your (resolved) path (ex. log it)
mine pointed after packaging to a pkg internal path

also https://github.com/zeit/pkg#snapshot-filesystem

I had this issue also and resolved it by creating directory "database" in my project directory.

var db = new sqlite3.Database( path.resolve(__dirname, 'db.sqlite') );

Hi folks! I'm also facing the same issue. Some times it works fine with my current configuration.
This is my knex configuration.

module.exports = {

development: {
client: 'sqlite3',
connection: {
filename: './src/database/db.sqlite'
}
},
...

This is my connection file:

const knex = require('knex');
const configuration = require('../../knexfile');
const connection = knex(configuration.development);
module.exports = connection;

The only way I found to solve the this issue is to delete the src/database/db.sqlite and create the db.sqlite again in the same path

Hi folks!

Thankfully after a tone of research I found the issue. To solve we have to use the absolute path on the database path like the following script:

development: {
client: 'sqlite3',
connection: {
filename: '/absolutepath/db.sqlite'
}

Thanks! was having the same problem. @sousadgaspar

Cara muito obrigado @sousadgaspar

Was this page helpful?
0 / 5 - 0 ratings

Related issues

j-brown picture j-brown  路  4Comments

bergheim picture bergheim  路  3Comments

Nilesh0101 picture Nilesh0101  路  4Comments

gillez picture gillez  路  4Comments

ByeongYeon picture ByeongYeon  路  4Comments