I’m getting an error when using the Pyodide library within my Obsidian plugin class. Below is the code I’m working with:
import { Plugin } from 'obsidian';
import { loadPyodide } from 'pyodide';
export default class MyPlugin extends Plugin {
async onload() {
console.log('My CUSTOM plugin');
process.browser = "obsidian";
const pyodide = await loadPyodide(
{
indexURL : "https://cdn.jsdelivr.net/pyodide/v0.26.4/full/"
}
);
await pyodide.loadPackage("micropip");
await pyodide.loadPackage("numpy");
console.log(pyodide);
console.log(pyodide.runPython('print("CUSTOM PRINT"); 1+1'));
this.registerMarkdownCodeBlockProcessor('pyodide', async (source, el, ctx) => {
pyodide.runPython(source);
});
}
}
When I start Obsidian, I get the following error:
Interestingly, if I disable and then re-enable the plugin from the list of plugins, it works as expected:
Why am I encountering this error when starting Obsidian, and how can I resolve it so that the plugin works correctly on the initial load without needing to disable and re-enable it?
Extra details
I added the following external node packages to the default esbuild.config.js
to avoid compilation errors:
node:path
node:fs
node:vm
node:promises
node:url
node:crypto
node:child_process
I’m new to javascript and bundles