Note: this is my first attempt to create a plugin in Obsidian - sorry if the mistake is obvious and I missed something key.
I am trying to create a file daylies.md
in a test vault, based on the obsidian-sample-plugin
, via:
export default class DayliesPlugin extends Plugin {
settings: MyPluginSettings;
async onload() {
await this.loadSettings();
const vault = new Vault();
// check if the dailies file exists and create it if not
if (vault.getFileByPath("daylies.md") === null) {
console.log("daylies.md does not exist, creating");
vault
.create("daylies.md", "")
.then(() => console.log("daylies.md created"))
.catch((err) =>
console.error(`cannot create daylies.md: ${err}`)
);
} else {
console.log("daylies.md exist");
}
(...)
What I get in the console (without the catch()
to give a full picture):
daylies.md does not exist, creating
app.js:1 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'exists')
at t.<anonymous> (app.js:1:732758)
at app.js:1:237228
at Object.next (app.js:1:237333)
at app.js:1:236249
at new Promise (<anonymous>)
at g (app.js:1:235994)
at t.create (app.js:1:732617)
at DayliesPlugin.onload (VM267 plugin:daylies:40:13)
Any idea where the problem could be?
EDIT/ I also tried the async
/await
version - same thing.