Error: Cannot find module 'obsidian'

Hello, I’d like to play with the dataview API on external dev env, but right from the start there appears to be a problem with the installation.
I did npm install -D obsidian-dataview.
But a simple code like

import { getAPI } from “obsidian-dataview”;
console.log(“test”)

I get the error Error: Cannot find module 'obsidian'. However, the module seems to be installed.

Maybe nothing direct related to your problem, but when I see something like that, those are my steps (and often is .env related):

  1. Check Installation:

    • Run npm install ... (or yarn add ...) to ensure the module is installed in your node_modules folder.
  2. Verify Import Path:

    • Confirm that your import statement is correct. Try to import “everything”:
      import * as ... from "...";
      
    • If it’s a specific path or alias, ensure that the path or alias is correctly configured in tsconfig.json.
  3. TypeScript Configuration:

    • Check if allowSyntheticDefaultImports is enabled in tsconfig.json, as Obsidian plugins sometimes require it:
      {
        "compilerOptions": {
          "allowSyntheticDefaultImports": true
        }
      }
      
  4. Check Your Workspace:

    • If you’re working on a plugin, ensure that you have the Obsidian Plugin API set up correctly. Sometimes, the obsidian module is available only in the actual Obsidian environment, rather than a standalone Node.js project.

This is a copy/paste from my checklist :slight_smile: … hope helps!

Cheers, Marko