TypeError: Cannot read properties of undefined (reading 'sys')

I am getting TypeError in this line of code: “case module.sys.contentType.sys.id”.
The same code is working fine in “the-example-app.nodejs” application. Can someone please help me to solve this issue. Thanks in advance. P.S I have pasted the full code of landingPage.pug at the bottom, down below


TypeError: G:\contentful\MERN-EXAMPLE\movies-app\server\views\landingPage.pug:19
17| if landingPage.fields.contentModules && landingPage.fields.contentModules.length
18| each module in landingPage.fields.contentModules

19| case module.sys.contentType.sys.id
20| when ‘layoutCopy’
21| +moduleCopy(module)
22|

Cannot read properties of undefined (reading ‘sys’)
at eval (eval at wrap (G:\contentful\MERN-EXAMPLE\movies-app\server\node_modules\pug-runtime\wrap.js:6:10), :565:32)
at eval (eval at wrap (G:\contentful\MERN-EXAMPLE\movies-app\server\node_modules\pug-runtime\wrap.js:6:10), :602:4)
at template (eval at wrap (G:\contentful\MERN-EXAMPLE\movies-app\server\node_modules\pug-runtime\wrap.js:6:10), :1026:7)
at Object.exports.renderFile (G:\contentful\MERN-EXAMPLE\movies-app\server\node_modules\pug\lib\index.js:454:38)
at Object.exports.renderFile (G:\contentful\MERN-EXAMPLE\movies-app\server\node_modules\pug\lib\index.js:444:21)
at View.exports.__express [as engine] (G:\contentful\MERN-EXAMPLE\movies-app\server\node_modules\pug\lib\index.js:493:11)
at View.render (G:\contentful\MERN-EXAMPLE\movies-app\server\node_modules\express\lib\view.js:135:8)
at tryRender (G:\contentful\MERN-EXAMPLE\movies-app\server\node_modules\express\lib\application.js:640:10)
at Function.render (G:\contentful\MERN-EXAMPLE\movies-app\server\node_modules\express\lib\application.js:592:3)
at ServerResponse.render (G:\contentful\MERN-EXAMPLE\movies-app\server\node_modules\express\lib\response.js:1012:7)
at module.exports.getLandingPage (G:\contentful\MERN-EXAMPLE\movies-app\server\routes\landingPage.js:34:12)
at runMicrotasks ()
at processTicksAndRejections (node:internal/process/task_queues:96:5)


landingPage.pug


extends layout

include mixins/_breadcrumb
include mixins/_editorialFeatures
include mixins/_moduleCopy
include mixins/_moduleHeroImage
include mixins/_moduleHighlightedCourse
include mixins/_emptyModule

block content
if currentPath !== ‘/’
.layout-centered
+breadcrumb
.layout-centered
+editorialFeatures(landingPage)
.modules-container
if landingPage.fields.contentModules && landingPage.fields.contentModules.length
each module in landingPage.fields.contentModules
case module.sys.contentType.sys.id
when ‘layoutCopy’
+moduleCopy(module)

      when 'layoutHeroImage'
        +moduleHeroImage(module)

      when 'layoutHighlightedCourse'
        +moduleHighlightedCourse(module, module.fields.course)
else
  +emptyModule()