# Slicemachine not working anymore when having node script with custom fetch implementation

**URL:** <https://community.prismic.io/t/slicemachine-not-working-anymore-when-having-node-script-with-custom-fetch-implementation/9373>\
**Category:** Developing with Prismic\
**Tags:** nodejs\
**Created:** [March 16, 2022, 10:38am UTC](https://community.prismic.io/t/slicemachine-not-working-anymore-when-having-node-script-with-custom-fetch-implementation/9373 "2022-03-16T10:38:39Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![marco3](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@marco3](https://community.prismic.io/u/marco3)\
**Post date:** [March 16, 2022, 10:38am UTC](https://community.prismic.io/t/slicemachine-not-working-anymore-when-having-node-script-with-custom-fetch-implementation/9373/1 "2022-03-16T10:38:39Z")

</div>

Inside my NextJS project I have a node script in `scripts/build-search.mjs` which fetches all my documents and indexes them for algolia.

Because that's outside of my NextJS environment I need a polyfill for fetch.

I Implemented it in the suggested way by using `node-fetch`.

```auto
import fetch from 'node-fetch'

...

const client = prismic.createClient(process.env.PRISMIC_API_ENDPOINT, {
    ...config,
    accessToken,
    routes: routeResolver.routes,
    fetch,
  })

```

Whenever I try to run the slice-machine now, I get this error:

> [slice-machine] /Users/marcokuehbauch/development/dieda-website/node\_modules/slice-machine-ui/build/server/src/index.js:141  
> undefined  
> ^  
> Error [ERR\_REQUIRE\_ESM]: require() of ES Module /Users/marcokuehbauch/development/dieda-website/node\_modules/node-fetch/src/index.js from /Users/marcokuehbauch/development/dieda-website/node\_modules/slice-machine-ui/build/server/src/index.js not supported.  
> Instead change the require of /Users/marcokuehbauch/development/dieda-website/node\_modules/node-fetch/src/index.js in /Users/marcokuehbauch/development/dieda-website/node\_modules/slice-machine-ui/build/server/src/index.js to a dynamic import() which is available in all CommonJS modules.  
> at Object.newLoader [as .js] (/Users/marcokuehbauch/development/dieda-website/node\_modules/pirates/lib/index.js:141:7)  
> at Object. (/Users/marcokuehbauch/development/dieda-website/node\_modules/slice-machine-ui/build/server/src/index.js:16:38) {  
> code: 'ERR\_REQUIRE\_ESM'

When I remove my node-fetch implementation completely and run `npm run slicemachine` again, the slicemachine works again.

Why are these related and do you have any idea, how I solve this?

---

<div class="post-metadata">

**Author:** ![Fares](https://avatars.discourse-cdn.com/v4/letter/f/71e660/32.png) [@Fares](https://community.prismic.io/u/Fares)\
**Post date:** [March 16, 2022, 6:15pm UTC](https://community.prismic.io/t/slicemachine-not-working-anymore-when-having-node-script-with-custom-fetch-implementation/9373/3 "2022-03-16T18:15:10Z")

</div>

Hi @marco3,

Thanks for reaching out,

In fact the error is telling you to use either Import or require but not both, can you try to replace `import fetch` by `require`?

---

<div class="post-metadata">

**Author:** ![marco3](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@marco3](https://community.prismic.io/u/marco3)\
**Post date:** [March 17, 2022, 8:31am UTC](https://community.prismic.io/t/slicemachine-not-working-anymore-when-having-node-script-with-custom-fetch-implementation/9373/4 "2022-03-17T08:31:12Z")

</div>

Hey @Fares

Unfortunately this didn't change the error. I also tried it with v2 of node-fetch and the async import as described in the docs [node-fetch - npm](https://www.npmjs.com/package/node-fetch).

I replaced node-fetch by cross-fetch and now slicemachine is working again. I have no clue why node-fetch and slicemachine don't like each other.

---

<div class="post-metadata">

**Author:** ![Fares](https://avatars.discourse-cdn.com/v4/letter/f/71e660/32.png) [@Fares](https://community.prismic.io/u/Fares)\
**Post date:** [March 17, 2022, 10:01am UTC](https://community.prismic.io/t/slicemachine-not-working-anymore-when-having-node-script-with-custom-fetch-implementation/9373/5 "2022-03-17T10:01:44Z")

</div>

Well, I've seen a similar issue before, and it turns out that it was related to the node-fetch version, please check [this topic reply](https://community.prismic.io/t/local-version-of-prismic-io-slow-wait-time-to-load/9040/5).

---

<div class="post-metadata">

**Author:** ![springtreedigital](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@springtreedigital](https://community.prismic.io/u/springtreedigital)\
**Post date:** [June 27, 2022, 7:48pm UTC](https://community.prismic.io/t/slicemachine-not-working-anymore-when-having-node-script-with-custom-fetch-implementation/9373/7 "2022-06-27T19:48:03Z")

</div>

Tracking this issue. While it is likely not a "huge" issue, using node-fetch@2.6.1 from September of 2020 seems like a potential issue and one that should be addressed by the Slice-Machine team.

---

<div class="post-metadata">

**Author:** ![Fares](https://avatars.discourse-cdn.com/v4/letter/f/71e660/32.png) [@Fares](https://community.prismic.io/u/Fares)\
**Post date:** [June 28, 2022, 2:33pm UTC](https://community.prismic.io/t/slicemachine-not-working-anymore-when-having-node-script-with-custom-fetch-implementation/9373/9 "2022-06-28T14:33:42Z")

</div>

Hi @springtreedigital

Thanks for letting us know; as you know, Slice Machine is an open source project, so feel free to raise an issue on the [Project page](https://github.com/prismicio/slice-machine) as well as PR if you would like to contribute.

On my side, I will check with Slice Machine team if there is a solution for this, but before all, can you please confirm that using the latest version of node-fetch still doesn't work?

---

<div class="post-metadata">

**Author:** ![springtreedigital](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@springtreedigital](https://community.prismic.io/u/springtreedigital)\
**Post date:** [June 28, 2022, 8:06pm UTC](https://community.prismic.io/t/slicemachine-not-working-anymore-when-having-node-script-with-custom-fetch-implementation/9373/10 "2022-06-28T20:06:14Z")

</div>

![image](https://europe1.discourse-cdn.com/flex013/uploads/prismic/original/2X/e/e95e755edbe1a500400e86431e512df0e1019393.jpeg)

Sure thing. Using latest version 3 of node-fetch. It's in their docs that if this is an issue, then just use the latest of version 2. I didn't know this at the time.

---

<div class="post-metadata">

**Author:** ![Fares](https://avatars.discourse-cdn.com/v4/letter/f/71e660/32.png) [@Fares](https://community.prismic.io/u/Fares)\
**Post date:** [July 5, 2022, 6:57am UTC](https://community.prismic.io/t/slicemachine-not-working-anymore-when-having-node-script-with-custom-fetch-implementation/9373/11 "2022-07-05T06:57:27Z")

</div>

Thanks for your reply,  
I have reported this to our dev team and I will let you know in case of any updates.

---

<div class="post-metadata">

**Author:** ![cptflammin](https://avatars.discourse-cdn.com/v4/letter/c/eada6e/32.png) [@cptflammin](https://community.prismic.io/u/cptflammin)\
**Post date:** [September 13, 2022, 8:53pm UTC](https://community.prismic.io/t/slicemachine-not-working-anymore-when-having-node-script-with-custom-fetch-implementation/9373/13 "2022-09-13T20:53:25Z")

</div>

Any update for support of v3 ?

---

<div class="post-metadata">

**Author:** ![Pau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/pau/32/5422_2.png) [@Pau](https://community.prismic.io/u/Pau)\
**Post date:** [September 14, 2022, 6:05pm UTC](https://community.prismic.io/t/slicemachine-not-working-anymore-when-having-node-script-with-custom-fetch-implementation/9373/15 "2022-09-14T18:05:47Z")

</div>

Hey @cptflammin, I suppose you're referring to Nuxt 3. Here are the updates we have for the moment:

> [@Slice Simulator Nuxt 3](https://community.prismic.io/t/slice-simulator-nuxt-3/10119/11):
>
> Hi Frank, Welcome to the community! So I don't have any hard dates on anything but here's what I know: Vue 3 SDK: it's in beta and will be published as latest in July. Nuxt 3 SDK: it's in alpha and will be published in beta next week. It supports everything and is as "prod ready" as Nuxt 3 is (RC-ish) Slice Simulator SDK: SDK for Vue 3 is available under @prismicio/slice-simulator-vue3 and is "prod ready" Slice Machine will have Vue 3 / Nuxt 3 support end of Summer. vue-essential-slices is …

---

<div class="post-metadata">

**Author:** ![cptflammin](https://avatars.discourse-cdn.com/v4/letter/c/eada6e/32.png) [@cptflammin](https://community.prismic.io/u/cptflammin)\
**Post date:** [September 19, 2022, 9:48am UTC](https://community.prismic.io/t/slicemachine-not-working-anymore-when-having-node-script-with-custom-fetch-implementation/9373/16 "2022-09-19T09:48:01Z")

</div>

Hey @Pau, no I am referring to the possibility to use node-fetch v3. Current workaround requires to downgrade to node-fetch v2

---

<div class="post-metadata">

**Author:** ![Pau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/pau/32/5422_2.png) [@Pau](https://community.prismic.io/u/Pau)\
**Post date:** [September 19, 2022, 10:33pm UTC](https://community.prismic.io/t/slicemachine-not-working-anymore-when-having-node-script-with-custom-fetch-implementation/9373/17 "2022-09-19T22:33:07Z")

</div>

I believe this is the same error: [`ERR_REQUIRE_ESM` error on `start-slicemachine` due to incorrect `node-fetch` version · Issue #467 · prismicio/slice-machine · GitHub](https://github.com/prismicio/slice-machine/issues/467)  
It hasn’t been addressed yet. It'll be good if you can share your use case in the GitHub issue as well, so the dev team can see it.

---

<div class="post-metadata">

**Author:** ![cptflammin](https://avatars.discourse-cdn.com/v4/letter/c/eada6e/32.png) [@cptflammin](https://community.prismic.io/u/cptflammin)\
**Post date:** [September 20, 2022, 12:26pm UTC](https://community.prismic.io/t/slicemachine-not-working-anymore-when-having-node-script-with-custom-fetch-implementation/9373/18 "2022-09-20T12:26:32Z")

</div>

@Pau Seems solved with latest helpers update [Type Error when building package that uses @prismicio/helpers - #10 by cptflammin](https://community.prismic.io/t/type-error-when-building-package-that-uses-prismicio-helpers/10938/10)
