Mobile obsidian's app.vault.adapter keeps changing its interface

What I’m trying to do

Use app.vault.adapter in dataviewjs queries to do more complex actions, such as creating and modifying notes. On Desktop this all works, and it used to work on mobile as well.
But first, path was no longer available on mobile. Now, I don’t have access to app.vault.adapter.getBasePath() and app.vault.adapter.fs contains no functions, it only has uri and dir, so I can’t use fs.readFileSync or fs.writeFileSync.

Things I have tried

Wrote a function to substitute the use of path, since it’s not available on mobile

function pathJoin(...paths) {
    return paths.join('/').replace(/\/\/+/g, '/');

Wrote a function to get base path differently, based on what is still available on mobile

function getVaultAbsolutePath() {
    return adapter.getBasePath?.() || adapter.basePath;

I am at my wit’s end. I don’t understand why the interface keeps changing on mobile. Please stop doing this.

Check out Why does fs.writeFile not save file? - #2 by joethei where joethei talks about how fs is not present on mobile platforms. So part of your issue is to be expected, although not documented on the Obsidian documentation site.

Not sure if something or what has happened to the path functions, but if we’re using parts of the API not documented, I’m thinking that’s a risk we’re taking. If it’s documented though, then deviations from the API could be considered a bug (or possibly unannounced change to the API).

We haven’t changed anything about the adapter interface in a long time.
There are actually two adapters, one for desktop, one for mobile.
fs is a thing on desktop, but that’s just an implementation detail, it’s not publicly exposed in the API and should not be used.

The methods documented here are available on both platforms: DataAdapter - Developer Documentation

I see, thank you. So I should be using read and write from app.vault.adapter. However, I can’t seem to be able to access normalizePath inside of a dataviewjs query. Is it not possible?

I tried to find it like this:

console.log("~1", app.vault?.adapter?.normalizePath)
console.log("~2", app.vault?.normalizePath)
console.log("~3", app?.normalizePath)

but all log undefined

normalizePath is a global function, those aren’t accessible to DV.
DVJS does have, that might do the same thing.

I was able to get it to work through read and write. I simply passed a relative path, without having to normalize it through a function.

i.e. const data = read(pathJoin("db", "gym", JSON_FILE_NAME));
Where pathJoin is just return paths.join('/').replace(/\/\/+/g, '/');

In order to use read and write in something rendered by dv.view, I had to bind adapter to them like so:

const { adapter } = app.vault;
const read =;
const write = adapter.write.bind(adapter);

Thanks for the assistance :smiley:
Thank you as well, you have been a great help since I joined the forums @holroy :blush:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.