While usign the getStaticPaths()
and getStaticProps()
I am getting the error NextJS: "TypeError: Cannot read property 'toLowerCase' of undefined"
NextJS: "TypeError: Cannot read property 'toLowerCase' of undefined"
1.2k views Asked by Juanma Menendez At
2
There are 2 answers
0
On
Somewhere in your file you might be using .toLowerCase() method and the conversion is not happening because the value is either undefined or not a string.
You can use something like Optional chaining (?.) operator to avoid this error.
You can learn more about optional chaining operator here
The problem was in getStaticPaths() I was directly returning an array of strings as paths:
Wrong Code
The solution was to return the paths array in a diffent structure:
Correct Code
myPageSlug
is the slug used when naming the page file, example: pages/[myPageSlug].tsx