@guiferviz that’s an interesting problem, difficult to debug
If we observe the compiled js
- From
Pyodidesources
var g = typeof process == "object" && typeof process.versions == "object" && typeof process.versions.node == "string" && !process.browser;
Here g will be true on the first run because process.browser is undefined
- You have in your code
process.browser = "obsidian";
but this code is executed AFTER the code I mentioned above, so the variable g is still true there
- From
Pyodidesources
async function T() {
if (!g || (V = (await import("node:url")).default, H = await import("node:fs"), D = await import("node:fs/promises"), z = (await import("node:vm")).default, L = await import("node:path"), U = L.sep, typeof O < "u"))
return;
let e = H, t = await import("node:crypto"), o = await Promise.resolve().then(() => __toESM(require_browser(), 1)), r = await import("node:child_process"), a = { fs: e, crypto: t, ws: o, child_process: r };
globalThis.require = function(n) {
return a[n];
};
}
As your g in (1) is true, the code tries to get import("node:url") and other node modules. And that’s causes your error.
However the subsequent times you try to load the plugin, your process.browser is already set in (2), and therefore g is false in (1) and the error in (3) doesn’t occur.
One of the ways to solve your issue is to patch the compiled main.js such that process.browser is set before the problematic code executes.
E.g. in esbuild.config.mjs
const banner =
`/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
process.browser = "obsidian"; // it's a dirty hack but it works
`;