1

After completion of project ,i run npm run build but unable to build error showing .

npm run build

> pcrf-portal@0.1.0 build
> react-scripts build

Creating an optimized production build...
Failed to compile.

Cannot read properties of undefined (reading 'includes')

i tried in my all codes but in codes no error is there.with includes. i'm expecting to build my project completely by running npm run build.

Ashutosh
  • 21
  • 1
  • I'm getting the same error. And there is no 'includes' word in my project. I suspect about npm versions but I'm not sure. – Emre Varol Mar 23 '23 at 19:12

2 Answers2

0

There might be a pretty good chance that the includes method you are using on a variable/function has initially not defined or not returning any value. That's how it's throwing the undefined. In such cases, You can use some sort of condition like if before calling the includes or you can declare some empty values to it initially.

rna
  • 426
  • 3
  • 6
  • if (jsonvalue != undefined && jsonvalue !== "") { if (value.toLowerCase().includes("date")) { const currentDate = jsonvalue.getFullYear().toString() + "-" + ("0" + (jsonvalue.getMonth() + 1)).slice(-2) + "-" + ("0" + jsonvalue.getDate()).slice(-2); jsonvalue = currentDate; } – Ashutosh Mar 23 '23 at 06:22
  • but if i have removed all the the includes also same error is showing while build. – Ashutosh Mar 23 '23 at 06:43
  • Please provide the error stack trace, so that we can try to figure out the actual issue or CSB if possible. – rna Mar 23 '23 at 18:15
0

try to find out where you have used .includes inside project. and lets say you are using like this

variable.includes

instead of this, use

variable?.includes
  • i used includes only the above only. – Ashutosh Mar 23 '23 at 07:53
  • if (jsonvalue != undefined && jsonvalue !== "") {if (value.toLowerCase().includes("date")) {const currentDate =jsonvalue.getFullYear().toString() +"-" +("0" + (jsonvalue.getMonth() + 1)).slice(-2) +"-" +("0" + jsonvalue.getDate()).slice(-2);jsonvalue = currentDate;}s = s + value + "=" + jsonvalue + "&"; displaySearchText =displaySearchText + value + " = " + jsonvalue + " & ";} – Ashutosh Mar 23 '23 at 08:11
  • `if (value?.toLowerCase().includes("date"))` try this – Shubham Nikam Mar 23 '23 at 10:23
  • if (value?.toLowerCase().includes("date")) i changed to this but same error is showing while building application. – Ashutosh Mar 24 '23 at 05:09
  • can you give me some context about what exactly the `value` is? I mean value variable is of which type int, string or something else? – Shubham Nikam Mar 24 '23 at 07:01
  • value typeof is string. – Ashutosh Mar 24 '23 at 07:57