Default export is not a function

What I’m trying to do

I am using Templater to populate a template file for meeting notes with some basic data (filename, topic, date, etc.) — I also want to use part of the filename (to be exact, the last word) for a frontend element called title.
The template looks somewhat like this:

let var_customer = await tp.system.prompt("Customer Name")

title: <% tp.user.getlastword( %>
date: <% tp.file.creation_date("YY-MM-DD") %>
tags: mtg_minutes


customer: <% var_customer %>

topic: <% tp.file.cursor() %>

As you can see, I have defined a JS function for the title based on the function getLastWord. That JS function is looking as follows:

function getLastWord(str) { 
// Split the string into an array of words 
	const words = str.split(' '); 
// Return the last word in the array 
	return words.pop(); 
module.exports = getLastWord();

However, when I am trying to use the template, I continuously get the error message “Default export is not a function”.

Things I have tried

I try to simply export the function via export = getLastWord(); - that does not work as well.

I am not quite sure what I am missing here - any help is highly appreciated :wink:

Thanks a lot!

Hey @svenschuldt,

Just encountered this same problem (while adding the IMdb Quickadd Macro) and the first hit of the same wording were both of your posts, both here and on reddit. I think I found the solution in the same search, provided by the indelible @Christian over on his GitHub Quickadd issue page:

Maybe you figured something out already, but perhaps this is still helpful to others.


This calls the getLastWord, but you’re supposed to only leave a reference to it.

So it should be:

module.exports = getLastWord;

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