# Jest Test always get error: Unable to load the module "ts-patch/compiler"

**URL:** <https://forum.heroiclabs.com/t/jest-test-always-get-error-unable-to-load-the-module-ts-patch-compiler/4837>\
**Category:** Runtime Framework\
**Created:** [January 5, 2024, 1:45pm UTC](https://forum.heroiclabs.com/t/jest-test-always-get-error-unable-to-load-the-module-ts-patch-compiler/4837 "2024-01-05T13:45:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mengxin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/mengxin/32/1879_2.png) [@mengxin](https://forum.heroiclabs.com/u/mengxin)\
**Post date:** [January 5, 2024, 1:45pm UTC](https://forum.heroiclabs.com/t/jest-test-always-get-error-unable-to-load-the-module-ts-patch-compiler/4837/1 "2024-01-05T13:45:58Z")

</div>

I am following the official doc of Jest testing

> **[Testing TypeScript Server Runtime Code with Jest](https://heroiclabs.com/docs/nakama/guides/server-framework/typescript-testing/)**
>
> Summary

but after run `npm run test`  
always get error:

```auto
 FAIL src/rpc-add-item.test.ts
  ● Test suite failed to run

    Unable to load the module "ts-patch/compiler". Using "ts-jest" requires this package to be installed. To fix it:
        ↳ install "ts-patch/compiler": `npm i -D ts-patch/compiler` (or `yarn add --dev ts-patch/compiler`)

```

 ![image](https://us1.discourse-cdn.com/flex020/uploads/heroiclabs/original/2X/7/7c6205e4f3580e421a7b3f2589c80f4ca87022bb.png)

I try to install `npm i -D ts-patch/compiler` but it is not exist. After do some research fo ts-patch, seem like this `ts-patch/compiler` is the live compiler of ts-patch.

Meanwhile, cannot find any example with jest test in github, could anyone help?

Btw, i am using the ts-patch 2.1.0 as the 3.x need TS \> 5.

---

<div class="post-metadata">

**Author:** ![mengxin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/mengxin/32/1879_2.png) [@mengxin](https://forum.heroiclabs.com/u/mengxin)\
**Post date:** [January 8, 2024, 3:27pm UTC](https://forum.heroiclabs.com/t/jest-test-always-get-error-unable-to-load-the-module-ts-patch-compiler/4837/2 "2024-01-08T15:27:54Z")

</div>

@ftkg i see this thread which you help to resolve, could you help to have a look? [ERROR node-builder RUN npx tsc on attemt to setup Jest - #8 by georgeneversleep](https://forum.heroiclabs.com/t/error-node-builder-run-npx-tsc-on-attemt-to-setup-jest/4438/8)

---

<div class="post-metadata">

**Author:** ![mengxin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/mengxin/32/1879_2.png) [@mengxin](https://forum.heroiclabs.com/u/mengxin)\
**Post date:** [January 24, 2024, 1:56pm UTC](https://forum.heroiclabs.com/t/jest-test-always-get-error-unable-to-load-the-module-ts-patch-compiler/4837/3 "2024-01-24T13:56:48Z")

</div>

any help? @novabyte

---

<div class="post-metadata">

**Author:** ![ftkg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/ftkg/32/1180_2.png) [@ftkg](https://forum.heroiclabs.com/u/ftkg)\
**Post date:** [January 24, 2024, 4:07pm UTC](https://forum.heroiclabs.com/t/jest-test-always-get-error-unable-to-load-the-module-ts-patch-compiler/4837/4 "2024-01-24T16:07:27Z")

</div>

> [@mengxin](#):
>
> Btw, i am using the ts-patch 2.1.0 as the 3.x need TS \> 5.

That is likely the cause you are facing errors, can you update to TS 5 and the latest ts-patch?

---

<div class="post-metadata">

**Author:** ![mengxin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/mengxin/32/1879_2.png) [@mengxin](https://forum.heroiclabs.com/u/mengxin)\
**Post date:** [January 24, 2024, 4:20pm UTC](https://forum.heroiclabs.com/t/jest-test-always-get-error-unable-to-load-the-module-ts-patch-compiler/4837/5 "2024-01-24T16:20:28Z")

</div>

we tried, but it got lots of compile error even for the demo script. I think all the demo code i found is use the TS \< 5.

---

<div class="post-metadata">

**Author:** ![mengxin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/mengxin/32/1879_2.png) [@mengxin](https://forum.heroiclabs.com/u/mengxin)\
**Post date:** [April 5, 2024, 9:58am UTC](https://forum.heroiclabs.com/t/jest-test-always-get-error-unable-to-load-the-module-ts-patch-compiler/4837/6 "2024-04-05T09:58:06Z")

</div>

Finally, make it work.

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [April 5, 2024, 12:30pm UTC](https://forum.heroiclabs.com/t/jest-test-always-get-error-unable-to-load-the-module-ts-patch-compiler/4837/7 "2024-04-05T12:30:28Z")

</div>

@mengxin if you can, please provide the steps you had to take as it can be helpful for the community 🙂.

---

<div class="post-metadata">

**Author:** ![mengxin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/mengxin/32/1879_2.png) [@mengxin](https://forum.heroiclabs.com/u/mengxin)\
**Post date:** [April 5, 2024, 2:23pm UTC](https://forum.heroiclabs.com/t/jest-test-always-get-error-unable-to-load-the-module-ts-patch-compiler/4837/8 "2024-04-05T14:23:30Z")

</div>

seems like it relates to the jest config and typescript version.  
i move the jest config from the package to an independent config file

I create a ts template repo

> **[GitHub - xinatcg/nakama-ts-template: Nakama Typescript Server Runtime Template](https://github.com/xinatcg/nakama-ts-template)**
>
> Nakama Typescript Server Runtime Template. Contribute to xinatcg/nakama-ts-template development by creating an account on GitHub.

hope it can help anyone who wants to use it. the official server template repo the ts part seem like not work.
