You need to enable JavaScript to run this app. 如何解决Rollup构建Electron应用的Node.js内置模块缺失垫片问题
优惠活动
大模型
产品
解决方案
定价
更多

如何解决Rollup构建Electron应用的Node.js内置模块缺失垫片问题

基于Rollup构建的Electron应用接入Knex+SQLite3的构建异常

场景说明

在基于Rollup构建的Electron应用中,通过Knex创建SQLite3数据库,核心初始化代码如下:

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;

构建异常表现

代码运行后触发Rollup构建警告,完整报错内容如下:

(!) 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 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')

已尝试的解决操作

按照报错提示安装rollup-plugin-node-polyfills插件,将其添加到rollup.config.js的插件配置列表后,构建警告无任何改善。


内容的提问来源于stack exchange,提问作者Chris

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.01 16:45:06