I’m trying to create a sqlite3 db using knex from inside an electron app built with rollup.
import knex from 'knex';
import 'sqlite3';
const database = knex({
client: 'sqlite3',
connection: {
filename: './games.sqlite'
},
useNullAsDefault: true
});
database.schema.hasTable('games').then(exists => {
if (!exists) {
return database.schema.createTable('games', t => {
t.increments('id').primary();
t.string('name', 100);
});
}
});
export default database;
As soon as this code is run I see the following warnings:
(!) Missing shims for Node.js built-ins
Creating a browser bundle that depends on 'util', 'events', 'stream', 'assert', 'timers', 'url', 'path', 'os' and 'buffer'. You might need to include https://github.com/ionic-team/rollup-plugin-node-polyfills
LiveReload enabled
(!) Missing global variable names
Use output.globals to specify browser global variable names corresponding to external modules
util (guessing 'util$6')
events (guessing 'require$$0$1')
stream (guessing 'require$$1')
assert (guessing 'assert')
timers (guessing 'timers_1')
url (guessing 'url')
fs (guessing 'fs')
path (guessing 'path$1')
child_process (guessing 'require$$0$2')
os (guessing 'os')
buffer (guessing 'buffer')
My read of this is that knex and/or sqlite3 is using a bunch of node built-ins and rollup needs to know how to bundle those. The suggested rollup-plugin-node-polyfills plugin sounds like it has been deprecated a few times over and is now replaced by @rollup/plugin-inject, but I don’t understand what I’m supposed to do with it in my rollup.config.js.
My guess would be
plugins: (
inject({
util: <<<<something>>>>,
events: <<<<something>>>>
etc etc
})
)
but none of my guesses for what those values should be have done much of anything.
rollup-plugin-node-polyfills also sounded promising but didn’t seem to work.