[Tex/LaTex] Listings – Error could not load requested style

listingsoverleafsharelatex

I am trying to create some styling for my javascript snippets. My configuration looks like:

\documentclass[letterpaper, dvipsnames]{article}
\usepackage[utf8]{inputenc}
\usepackage{listings} % Package for adding javascript code with code highlighting
\usepackage[dvipsnames]{xcolor} % Package for adding colors
\definecolor{purple}{rgb}{0.65, 0.12, 0.82}
\definecolor{main-color}{rgb}{0.6627, 0.7176, 0.7764}
\definecolor{back-color}{rgb}{0.1686, 0.1686, 0.1686}

\lstdefinestyle{codeSection}
{
  language= JavaScript,
  basicstyle = {\ttfamily \color{main-color}},
  backgroundcolor = {\color{back-color}},
  commentstyle = {\color{OliveGreen}},
  stringstyle = {\color{green}},
  keywordstyle = {\color{orange}\bfseries},
  keywordstyle = [2]{\color{orange}},
  keywordstyle = [3]{\color{purple}},
  keywordstyle = [4]{\color{lime}},
  keywordstyle = [5]{\color{orange}},
  keywords = {typeof, new, true, false, function, return, null, switch, var, if, in, while, do, else, case, break, class, export, boolean, throw, implements, import, this, constructor, string, number, public, private, static, const, var, let, void},
  morekeywords = [2]{class, export, boolean, throw, implements, import, this, interface},
  morekeywords = [3]{Promise, Observable},
  morekeywords = [4]{console},
  otherkeywords = {;},
  comment = [l]{//},
  morecomment = [s]{/*}{*/},
  morestring = [b]',
  morestring = [b]",
  sensitive = false,
  breaklines = true,
  showstringspaces= false,
  showspaces= false,
  extendedchars= true
}

Now when I try to add some Code it renders with the correct styling, but it gives me the error:Could not load requested styling. The Code-insertion looks like:

\begin{document}
\begin{figure}[H]
\begin{lstlisting}[style=codeSection]
export interface FakeHttpResponse {
    code: string;
    message: string;
}

const scndPromise = new Promise<FakeHttpResponse>((resolve, reject) => {
    setTimeout(() => {
        resolve({
            code: '200',
            message: 'Promise kept!'
        });
    }, 10 * 1000);
});

console.log(scndPromise);
setTimeout(() => console.log(scndPromise), 10 * 1000);
\end{lstlisting}
\end{figure}
\end{document}

Can anyone help me out on fixing this error?

Best Answer

I fixed it by the following configuration:

\lstdefinelanguage{JavaScript}
{
  keywords = {typeof, new, true, false, function, return, null, switch, var, if, in, while, do, else, case, break, class, export, boolean, throw, implements, import, this, constructor, string, number, public, private, static, const, var, let, void},
  morekeywords = [2]{class, export, boolean, throw, implements, import, this, interface},
  morekeywords = [3]{Promise, Observable},
  morekeywords = [4]{log},
  otherkeywords = {;},
  comment = [l]{//},
  morecomment = [s]{/*}{*/},
  morestring = [b]',
  morestring = [b]",
}

\lstset
{
  language= JavaScript,
  commentstyle = {\color{OliveGreen}},
  stringstyle = {\color{green}},
  keywordstyle = {\color{orange}\bfseries},
  keywordstyle = [2]{\color{orange}},
  keywordstyle = [3]{\color{purple}},
  keywordstyle = [4]{\color{lime}},
  keywordstyle = [5]{\color{orange}},
  basicstyle = {\ttfamily \color{main-color}},
  backgroundcolor = {\color{back-color}},    
  sensitive = false,
  breaklines = true,
  showstringspaces= false,
  showspaces= false,
  extendedchars= true
}