# Integrating the Javascript SDK with Common JS module

**URL:** <https://community.temporal.io/t/integrating-the-javascript-sdk-with-common-js-module/3852>\
**Category:** Community Support\
**Tags:** java-sdk\
**Created:** [January 28, 2022, 2:54pm UTC](https://community.temporal.io/t/integrating-the-javascript-sdk-with-common-js-module/3852 "2022-01-28T14:54:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![pratik](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/pratik/32/1648_2.png) [@pratik](https://community.temporal.io/u/pratik)\
**Post date:** [January 28, 2022, 2:54pm UTC](https://community.temporal.io/t/integrating-the-javascript-sdk-with-common-js-module/3852/1 "2022-01-28T14:54:41Z")

</div>

Our application uses CommonJS module and is built on top of node 14. The npm package is built using ESM. Is there a recommended way to include it as a CommonJS module?

Getting a lot of errors while trying to transpile using babel. Has anyone here done this before?

---

<div class="post-metadata">

**Author:** ![swyx](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/swyx/32/210_2.png) [@swyx](https://community.temporal.io/u/swyx)\
**Post date:** [January 28, 2022, 6:54pm UTC](https://community.temporal.io/t/integrating-the-javascript-sdk-with-common-js-module/3852/2 "2022-01-28T18:54:33Z")

</div>

not done before, but am interested in making it work. what do you mean by EJS please? i only know [EJS](https://ejs.co/) as javascript templates, but that doesnt make sense for npm packages

---

<div class="post-metadata">

**Author:** ![pratik](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/pratik/32/1648_2.png) [@pratik](https://community.temporal.io/u/pratik)\
**Post date:** [January 28, 2022, 7:10pm UTC](https://community.temporal.io/t/integrating-the-javascript-sdk-with-common-js-module/3852/3 "2022-01-28T19:10:06Z")

</div>

Sorry that was a typo. I meant ESM.

The `import` syntax cannot be mixed with `require` and I need the temporalio SDK to be transpiled to CommonJS.

---

<div class="post-metadata">

**Author:** ![loren](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/loren/32/5099_2.png) [@loren](https://community.temporal.io/u/loren)\
**Post date:** [January 28, 2022, 10:42pm UTC](https://community.temporal.io/t/integrating-the-javascript-sdk-with-common-js-module/3852/4 "2022-01-28T22:42:30Z")

</div>

Hi pratik, you should find that the Temporal npm packages define exports in a [CJS-compatible way](https://nodejs.org/api/modules.html#modules-commonjs-modules), by adding properties to `exports`:

```auto
less node_modules/@temporalio/client/lib/workflow-client.js
...
exports.WorkflowClient = WorkflowClient;

```

Also, in our hello-world sample, you can see this working: during the build step, our TS import statements are compiled to `require()` statements, for instance in `lib/client.js`:

```auto
const client_1 = require("@temporalio/client");

```

If you can share the repo or the errors, I might be able to help further 😌

---

<div class="post-metadata">

**Author:** ![pratik](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/pratik/32/1648_2.png) [@pratik](https://community.temporal.io/u/pratik)\
**Post date:** [January 31, 2022, 7:13am UTC](https://community.temporal.io/t/integrating-the-javascript-sdk-with-common-js-module/3852/5 "2022-01-31T07:13:07Z")

</div>

Thanks @loren

I was able to make it work using the CommonJS syntax i.e `require`.

I was working on a project that was developed on `node@10.x` where it would not work out of the box. Moved to another project that was using `node@14.x`.

---

<div class="post-metadata">

**Author:** ![loren](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/loren/32/5099_2.png) [@loren](https://community.temporal.io/u/loren)\
**Post date:** [January 31, 2022, 5:04pm UTC](https://community.temporal.io/t/integrating-the-javascript-sdk-with-common-js-module/3852/6 "2022-01-31T17:04:43Z")

</div>

You’re welcome! Yeah, the SDK only supports Node v14+. Here are a couple samples that might be relevant:

Un-transpiled JS with `import`s: [samples-typescript/hello-world-js at main · temporalio/samples-typescript · GitHub](https://github.com/temporalio/samples-typescript/tree/main/hello-world-js)

TS & ESM: [samples-typescript/fetch-esm at main · temporalio/samples-typescript · GitHub](https://github.com/temporalio/samples-typescript/tree/main/fetch-esm)

---

<div class="post-metadata">

**Author:** ![pratik](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/pratik/32/1648_2.png) [@pratik](https://community.temporal.io/u/pratik)\
**Post date:** [February 1, 2022, 1:25pm UTC](https://community.temporal.io/t/integrating-the-javascript-sdk-with-common-js-module/3852/7 "2022-02-01T13:25:13Z")

</div>

Thanks, @loren - Would you also have TS/JS examples for SAGA implementations with Temporal?

I can see that the Java Client supports SAGA out of the box: [samples-java/TripBookingWorkflowImpl.java at main · temporalio/samples-java · GitHub](https://github.com/temporalio/samples-java/blob/main/src/main/java/io/temporal/samples/bookingsaga/TripBookingWorkflowImpl.java)

---

<div class="post-metadata">

**Author:** ![loren](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/loren/32/5099_2.png) [@loren](https://community.temporal.io/u/loren)\
**Post date:** [February 1, 2022, 4:54pm UTC](https://community.temporal.io/t/integrating-the-javascript-sdk-with-common-js-module/3852/8 "2022-02-01T16:54:09Z")

</div>

No sample yet. You could certainly code a SAGA with the current SDK, but I also opened an FR to provide helpers for it. Feel free to chime in if you have API ideas 😌 [[Feature Request] Add SAGA helpers? · Issue #456 · temporalio/sdk-typescript · GitHub](https://github.com/temporalio/sdk-typescript/issues/456)
