You're probably not indenting your heredoc with tabs. Every line of the heredoc must be indented with a tab, including the first line (where the delimiter is introduced). Here is a test case for you:
echo -e 'function heredoc() {\
\tcat <<-HEREDOC\
\t\tThis is a test\tHEREDOC\
} heredoc' > heredoc.sh
Try running that command and then running `heredoc.sh`. You should get the following output:
This is a test.
Alternatively, here is the same script but with the first line indented with spaces instead of a tab:
echo -e 'function heredoc() {\
cat <<-HEREDOC\
\t\tThis is a test\tHEREDOC\
} heredoc' > heredoc2.sh
If we run `heredoc2.sh` we get the following error output:
bash heredoc2.sh
heredoc2.sh: line 4: warning: here-document at line 2 delimited by end-of-file (wanted `HEREDOC')
heredoc2.sh: line 5: syntax error: unexpected end of file