2025-10-21 00:52:50 +00:00
|
|
|
// Plugin to provide a shim for node:module in browser/Electron renderer context
|
|
|
|
|
const nodeModuleShim = {
|
|
|
|
|
name: "node-module-shim",
|
|
|
|
|
setup(build) {
|
2026-05-19 21:55:21 +00:00
|
|
|
// Intercept node:module / module imports and provide a shim. Both prefixed
|
|
|
|
|
// and bare forms are matched — @anthropic-ai/claude-agent-sdk imports the
|
|
|
|
|
// bare form, while @langchain/community uses node:module.
|
|
|
|
|
build.onResolve({ filter: /^(node:)?module$/ }, (args) => {
|
2025-10-21 00:52:50 +00:00
|
|
|
return {
|
|
|
|
|
path: args.path,
|
|
|
|
|
namespace: "node-module-shim",
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
build.onLoad({ filter: /.*/, namespace: "node-module-shim" }, () => {
|
|
|
|
|
return {
|
|
|
|
|
contents: `
|
|
|
|
|
// Shim for node:module in Electron/Obsidian environment (CommonJS format)
|
|
|
|
|
module.exports = {
|
|
|
|
|
createRequire: function(filename) {
|
|
|
|
|
// In Electron renderer, we can use the global require
|
|
|
|
|
// Note: filename parameter is ignored (may be undefined from @langchain/community v1.0.0)
|
|
|
|
|
if (typeof require !== 'undefined') {
|
|
|
|
|
return require;
|
|
|
|
|
}
|
|
|
|
|
// Fallback: return a function that throws a helpful error
|
|
|
|
|
return function shimmedRequire(id) {
|
|
|
|
|
throw new Error('Dynamic require of "' + id + '" is not supported in this environment');
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
`,
|
|
|
|
|
loader: "js",
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default nodeModuleShim;
|