[Tex/LaTex] lastpage package: incompatibility with nameref package

cross-referencingerrorslastpage

When I try to use the nameref package together with the lastpage package (version earlier than 2013/01/28, of course) I have following two errors:

! Package lastpage Error: no auxiliary file allowed
! Extra \else

But without the nameref package (and referencing chapters by names) my LaTeX document builds without problems.
What does this error mean? And what are possible causes?

My document file:

\documentclass[a4paper,oneside,12pt]{report}
\usepackage[polish]{babel}
\usepackage[latin2]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{setspace}
\usepackage{indentfirst}
\usepackage{titlesec}
\usepackage{nameref}
\usepackage{lastpage}
\usepackage{fancyhdr}
\onehalfspacing
\titleformat*{\section}{\normalsize\bfseries}
\setlength{\parindent}{1cm}
\begin{document}
\pagestyle{plain}
Text.
%\input{./title.tex}
\pagenumbering{arabic}
\fancypagestyle{plain}{% 
    \fancyhf{}
        \fancyfoot[C]{Strona \normalsize\thepage\ z \pageref{LastPage}}
    \renewcommand{\headrulewidth}{0pt} % remove line between header and main text
}
\tableofcontents
\listoffigures
\pagestyle{plain}
Text.
%\input{./ch1.tex}
%\input{./ch2.tex}
%\input{./ch3.tex}
%\input{./ch4.tex}
%\input{./biblio.tex}
\end{document}

Best Answer

For some reasons, nameref and lastpage fight each other when trying to do something to the .aux file just before finishing.

All works if you say

\usepackage{zref-user,zref-lastpage}

instead of \usepackage{lastpage} and

\fancypagestyle{plain}{%
  \fancyhf{}
  \fancyfoot[C]{\normalsize Strona \thepage\ z \zpageref{LastPage}}
  \renewcommand{\headrulewidth}{0pt} % remove line between header and main text
}

Note the command \zpageref. (Also \normalsize should go before Strona).