Skip to content

Commit cea1126

Browse files
vveerrggclaude
andcommitted
fix: add process shim for Node.js libraries in browser context
Inject a minimal process shim via esbuild to resolve "process is not defined" errors from nostr-crypto-utils transitive deps (crypto-browserify, readable-stream, etc.) in Chrome MV3 service worker. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 670cb5e commit cea1126

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

build.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ const chromeEntryPoints = {
3434

3535
const shared = {
3636
bundle: true,
37+
inject: [`${SRC}/shims/process.js`],
38+
define: {
39+
'global': 'globalThis',
40+
},
3741
plugins: [{
3842
name: 'node-module-stubs',
3943
setup(build) {

src/shims/process.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Minimal process shim for browser context.
3+
* Node.js libraries bundled via nostr-crypto-utils (crypto-browserify,
4+
* readable-stream, etc.) reference the global `process` object.
5+
* This provides just enough for them to work in a browser extension.
6+
*/
7+
export var process = {
8+
env: { NODE_ENV: 'production', LOG_LEVEL: 'warn' },
9+
browser: true,
10+
version: '',
11+
stdout: null,
12+
stderr: null,
13+
nextTick: function (fn) {
14+
var args = Array.prototype.slice.call(arguments, 1);
15+
Promise.resolve().then(function () { fn.apply(null, args); });
16+
},
17+
};

0 commit comments

Comments
 (0)