Help - Reference Error: Can't find variable: require on ios


I am having an error on mobile when I try displaying a view that uses a .js file where my common utility functions are defined. I have used the accepted answer in this post DataviewJs - Code reuse: common place for scripts - Basement - Obsidian Forum for reusing my common utility functions in other views.

What I am trying to achieve is: Being able to import the common utility functions inside the view.js files in a way that it also works on mobile.

I am using dataviewjs blocks in my template files in combination with templater. My template files are calling the views with inputs like the current date, tags to be used in filtering etc. Inside my view.js files, I import my utility functions using commonjs require syntax. I create tables or task lists using dv.table or dv.taskList where I use my helper functions for handle common formatting/filtering tasks sucjh as filtering tasks with specific tags, filtering tasks completed on a date, adding new lines to the text inside a table cell so that they fit the screen etc.

While this works perfectly on desktop, it fails on ios with the following error


const dataviewUtils = require(app.vault.adapter.basePath +

const tag = input["tag"];
const date = input["date"];
const lastWeekDay = dataviewUtils.getLastWeekDay(date);

// Display completed tasks
    .file.tasks.where((t) => t.completed)
    .where((t) => t.text.includes(lastWeekDay))
    .groupBy((p) => (p = "completed tasks"))


function getLastWeekDay(currentDateString) {
  const currentDate = new Date(currentDateString);
  const currentDayOfWeek = currentDate.getDay();

  const daysToGoBack = currentDayOfWeek === 1 ? 3 : currentDayOfWeek === 0 ? 2 : 1;
  const lastWeekDay = new Date(currentDate.getTime() - daysToGoBack * 24 * 60 * 60 * 1000);

  return lastWeekDay.toLocaleDateString("en-CA");
module.exports = getLastWeekDay;

daily template

# daily updates

## yesterday

await dv.view("views/doneYesterday", {tag: "#daily", date: "<% %>"});

Getting the same problem here, did you find any solution?

I hit this error too on Android a week or 2 ago and the experience is today is slightly different since I have made some changes to my common .js files, and I get a “can’t read…” error of some variable because the object that was imported by the require is undefined. You are not alone.

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