# TypeError: Cannot read properties of undefined (reading 'Mode')

**URL:** <https://pdfjs.community/t/typeerror-cannot-read-properties-of-undefined-reading-mode/1988>\
**Category:** Technical Support\
**Created:** [August 27, 2022, 6:32pm UTC](https://pdfjs.community/t/typeerror-cannot-read-properties-of-undefined-reading-mode/1988 "2022-08-27T18:32:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dcheli](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@dcheli](https://pdfjs.community/u/dcheli)\
**Post date:** [August 27, 2022, 6:32pm UTC](https://pdfjs.community/t/typeerror-cannot-read-properties-of-undefined-reading-mode/1988/1 "2022-08-27T18:32:04Z")

</div>

**Which product are you using?**  
PDF.js Express Plus

**PDF.js Express Version**  
“@pdftron/pdfjs-express”: “^7.3.9”,

**Detailed description of issue**  
I am receiving the error message TypeError: Cannot read properties of undefined (reading ‘Mode’) when trying to set the following const for docViewer.textSearchInit  
const { docViewer, Annotations, CoreControls } = instance;

const searchMode = CoreControls.Search.Mode.PAGE\_STOP | CoreControls.Search.Mode.HIGHLIGHT;

Additionally, the code snippet above is from your samples.

**Expected behaviour**  
I expect that the properties are found.

**Does your issue happen with every document, or just one?**  
Every document

**Link to document**  
I cannot because it contains sensitive information and I don’t think it’s relevant  
**Code snippet**  
const { docViewer, Annotations, CoreControls } = instance;

const searchMode = CoreControls.Search.Mode.PAGE\_STOP | CoreControls.Search.Mode.HIGHLIGHT;

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/1X/ffbcd25c7d423db8d5acd5db201c272f4db306dd.png) [@system](https://pdfjs.community/u/system)\
**Post date:** [August 27, 2022, 6:32pm UTC](https://pdfjs.community/t/typeerror-cannot-read-properties-of-undefined-reading-mode/1988/3 "2022-08-27T18:32:09Z")

</div>

**Hello, I’m Ron, an automated tech support bot 🤖**

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:
- [Core engine for WebViewer - Creating your own UI using WebViewer Core](https://pdfjs.express/documentation/ui-customization/core#creating-your-own-ui-using-webviewer-core)
- [Default UI for WebViewer - How it works behind the scenes](https://pdfjs.express/documentation/ui-customization/default-ui#how-it-works-behind-the-scenes)
- [Rich text](https://pdfjs.express/documentation/annotation/rich-text.8)

APIs:
- [UndefinedsearchInProgress](https://pdfjs.express/api/namespaces.list.html#event:searchInProgress__anchor)
- [Core.DisplayMode - new DisplayMode(docViewer, mode [, scrollable])](https://pdfjs.express/api/Core.DisplayMode.html#DisplayMode__anchor)
- [Core.Tools.MarqueeZoomTool - new MarqueeZoomTool(docViewer)](https://pdfjs.express/api/Core.Tools.MarqueeZoomTool.html#MarqueeZoomTool__anchor)

Forums:
- [Search a keyword and annotate it programmatically](https://pdfjs.community/t/search-a-keyword-and-annotate-it-programmatically/691/4)
- [PDF is displayed without previous annotations](https://pdfjs.community/t/pdf-is-displayed-without-previous-annotations/1738/1)
- [Error when loading base64 document](https://pdfjs.community/t/error-when-loading-base64-document/1577/1)

  
  

Share how you are using PDF.js Express in your organization you could win a **$500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free**. Learn more [here](https://utm.guru/ueQNw)

---

<div class="post-metadata">

**Author:** ![tgordon](https://avatars.discourse-cdn.com/v4/letter/t/aca169/32.png) [@tgordon](https://pdfjs.community/u/tgordon)\
**Post date:** [August 29, 2022, 7:24pm UTC](https://pdfjs.community/t/typeerror-cannot-read-properties-of-undefined-reading-mode/1988/4 "2022-08-29T19:24:17Z")

</div>

Hello dcheli,

Welcome to the PDFJS Express forum!

You can access the search modes with the latest version by doing:

```javascript
instance.Core.Search.Mode.PAGE_STOP

```

Which sample has this code snippet?  
Let me know if this works for you

Best regards,  
Tyler Gordon  
Web Development Support Engineer  
PDFTron

Share how you are using PDF.js Express in your organization you could win a **$500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free**. Learn more [here](https://utm.guru/ueQNw)

---

<div class="post-metadata">

**Author:** ![dcheli](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@dcheli](https://pdfjs.community/u/dcheli)\
**Post date:** [August 29, 2022, 10:25pm UTC](https://pdfjs.community/t/typeerror-cannot-read-properties-of-undefined-reading-mode/1988/5 "2022-08-29T22:25:06Z")

</div>

This is the documentation that contains the code snippet.  
[Advanced Search | Documentation (pdfjs.express)](https://pdfjs.express/documentation/search/advanced-search)

---

<div class="post-metadata">

**Author:** ![tgordon](https://avatars.discourse-cdn.com/v4/letter/t/aca169/32.png) [@tgordon](https://pdfjs.community/u/tgordon)\
**Post date:** [August 30, 2022, 4:58pm UTC](https://pdfjs.community/t/typeerror-cannot-read-properties-of-undefined-reading-mode/1988/6 "2022-08-30T16:58:12Z")

</div>

Hello dcheli,

Thank you for sending this, it looks like this guide is for version 8.0+ with the new namespace changes.

Best regards,  
Tyler Gordon  
Web Development Support Engineer  
PDFTron

Share how you are using PDF.js Express in your organization you could win a **$500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free**. Learn more [here](https://utm.guru/ueQNw)

---

<div class="post-metadata">

**Author:** ![dcheli](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@dcheli](https://pdfjs.community/u/dcheli)\
**Post date:** [August 30, 2022, 8:01pm UTC](https://pdfjs.community/t/typeerror-cannot-read-properties-of-undefined-reading-mode/1988/7 "2022-08-30T20:01:48Z")

</div>

Hey Tyler,  
If you change the version on the page to 7.x.x you will see what I’m referring to (see below). I am using 7.3.9

```javascript
const searchMode = CoreControls.Search.Mode.PAGE_STOP | CoreControls.Search.Mode.HIGHLIGHT;;

```

---

<div class="post-metadata">

**Author:** ![tgordon](https://avatars.discourse-cdn.com/v4/letter/t/aca169/32.png) [@tgordon](https://pdfjs.community/u/tgordon)\
**Post date:** [August 31, 2022, 6:11pm UTC](https://pdfjs.community/t/typeerror-cannot-read-properties-of-undefined-reading-mode/1988/8 "2022-08-31T18:11:43Z")

</div>

Hello dcheli,

My apologies, completely forgot to switch the version.

I wasnt able to get the error to occur with that whole snippet. Can you try with the latest build of v7.3.9?  
Performing `npm install @pdftron/pdfjs-express@7.3.9` should get the latest build.

Best regards,  
Tyler Gordon  
Web Development Support Engineer  
PDFTron

Share how you are using PDF.js Express in your organization you could win a **$500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free**. Learn more [here](https://utm.guru/ueQNw)
