| name | obsidian-common-errors |
| description | Diagnose and fix common Obsidian plugin errors and exceptions.
Use when encountering plugin errors, debugging failed operations,
or troubleshooting Obsidian plugin issues.
Trigger with phrases like "obsidian error", "fix obsidian plugin",
"obsidian not working", "debug obsidian plugin".
|
| allowed-tools | Read, Grep, Bash(node:*) |
| version | 1.0.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
Obsidian Common Errors
Overview
Quick reference for the most common Obsidian plugin errors and their solutions.
Prerequisites
- Obsidian plugin development environment set up
- Access to Developer Console (Ctrl/Cmd+Shift+I)
- Plugin source code access
Instructions
Step 1: Open Developer Console
Press Ctrl+Shift+I (Windows/Linux) or Cmd+Option+I (macOS) to open Developer Tools.
Step 2: Identify the Error
Check the Console tab for red error messages related to your plugin.
Step 3: Match Error to Solutions Below
Find your error type and apply the fix.
Error Handling
TypeError: Cannot read properties of undefined
Error Message:
TypeError: Cannot read properties of undefined (reading 'xyz')
Cause: Accessing a property on a null/undefined object, often when vault or workspace isn't ready.
Solution:
const file = this.app.workspace.getActiveFile();
const content = await this.app.vault.read(file);
const file = this.app.workspace.getActiveFile();
if (!file) {
new Notice('No file is currently open');
return;
}
const content = await this.app.vault.read(file);
Plugin failed to load
Error Message:
Plugin 'my-plugin' failed to load
Causes and Solutions:
- Syntax error in main.js:
node -c main.js
- Missing manifest.json fields:
{
"id": "my-plugin",
"name": "My Plugin",
"version": "1.0.0",
"minAppVersion": "1.0.0",
"description": "...",
"author": "Your Name"
}
- No default export:
export class MyPlugin extends Plugin { }
export default class MyPlugin extends Plugin { }
This plugin failed to load and has been disabled
Error Message:
This plugin failed to load and has been disabled. Check the developer console for more information.
Common Causes:
- Runtime error in onload():
async onload() {
const data = await someAsyncOperation();
}
async onload() {
try {
const data = await someAsyncOperation();
} catch (error) {
console.error('Failed to load data:', error);
new Notice('Plugin initialization failed');
}
}
- Incorrect module import:
import { Something } from 'wrong-package';
external: ['obsidian', 'electron', '@codemirror/*', '@lezer/*'],
Command not found / Command not registered
Error Message:
Command 'my-plugin:my-command' not found
Cause: Command not registered or wrong command ID.
Solution:
this.addCommand({
id: 'my-command',
name: 'My Command',
callback: () => {
},
});
View type not registered
Error Message:
View type 'custom-view' not registered
Cause: Trying to use a view before registering it.
Solution:
async onload() {
this.registerView(
VIEW_TYPE_CUSTOM,
(leaf) => new CustomView(leaf)
);
this.addCommand({
id: 'open-view',
name: 'Open View',
callback: () => this.activateView(),
});
}
Settings not persisting
Error Message: No error, but settings reset on reload.
Cause: Missing saveData() call or wrong data structure.
Solution:
this.settings.myOption = newValue;
this.settings.myOption = newValue;
await this.saveSettings();
async saveSettings() {
await this.saveData(this.settings);
}
async loadSettings() {
this.settings = Object.assign(
{},
DEFAULT_SETTINGS,
await this.loadData()
);
}
File not found / Path errors
Error Message:
Error: ENOENT: no such file or directory
Cause: Incorrect file path or file doesn't exist.
Solution:
const file = this.app.vault.getAbstractFileByPath(path);
if (!file) {
new Notice(`File not found: ${path}`);
return;
}
if (!(file instanceof TFile)) {
new Notice(`Not a file: ${path}`);
return;
}
const content = await this.app.vault.read(file);
Memory leaks / Event handlers not cleaned up
Symptoms: Plugin slows down, duplicate events firing.
Cause: Event listeners not properly removed.
Solution:
document.addEventListener('click', this.handleClick);
this.registerDomEvent(document, 'click', this.handleClick.bind(this));
this.app.workspace.on('file-open', callback);
this.registerEvent(
this.app.workspace.on('file-open', callback)
);
Build errors: Cannot find module 'obsidian'
Error Message:
Cannot find module 'obsidian' or its corresponding type declarations
Solution:
npm install obsidian@latest
{
"compilerOptions": {
"moduleResolution": "node",
"types": ["node"]
}
}
external: ['obsidian'],
Examples
Debug Logging Helper
const DEBUG = true;
function debug(...args: any[]) {
if (DEBUG) {
console.log('[MyPlugin]', ...args);
}
}
debug('Loading settings', this.settings);
debug('Processing file', file.path);
Quick Diagnostic Commands
this.addCommand({
id: 'debug-dump-settings',
name: 'Debug: Dump Settings',
callback: () => {
console.log('Settings:', JSON.stringify(this.settings, null, 2));
}
});
this.addCommand({
id: 'debug-list-views',
name: 'Debug: List Open Views',
callback: () => {
const leaves = this.app.workspace.getLeavesOfType('markdown');
console.log('Open views:', leaves.length);
leaves.forEach(leaf => {
console.log('-', leaf.view.file?.path);
});
}
});
Escalation Path
- Check Developer Console for errors
- Collect evidence with
obsidian-debug-bundle
- Search Obsidian Forum
- Check GitHub Issues
- Ask in Obsidian Discord
Resources
Next Steps
For comprehensive debugging, see obsidian-debug-bundle.