Replies: 1 comment
|
Coming back to this one very late - sorry about that. The reason nothing you tried worked: your script isn't loaded by Node's module system, so Two patterns that do work: Option A - require by absolute path. Run module.exports = async ({ app }) => {
const path = require("path");
const simpleGit = require(
path.join(app.vault.adapter.getBasePath(), "scripts", "node_modules", "simple-git")
);
const git = simpleGit(app.vault.adapter.getBasePath());
// ... git.add("./*").commit("...").push() etc.
};Option B - bundle. Build your script into a single file and point QuickAdd at the bundle, so no Either way this is desktop-only: The require-by-absolute-path pattern and its caveats are documented here: https://quickadd.obsidian.guide/docs/UserScripts |
Uh oh!
There was an error while loading. Please reload this page.
I have a user script macro that uses simple-git to push changes to github. I am struggling on how to reference the simple-git dependency.
I've tried doing an
npm i simple-gitin the same directory as the script file, in the parent directory, in the.obsidian/modulesdirectory. I've even tried copying the index.js file from simple-git into the same folder as my user script and doingconst simpleGit = require('./simple-git')Nothing seems to work. The error is always "cannot find module 'simple-git'"
node:internal/modules/cjs/loader:1082 Uncaught (in promise) Error: Cannot find module 'simple-git' Require stack: - electron/js2c/renderer_initAny tricks on how to reference dependencies in user script macros?
All reactions