# Absinthe/Socket : JS Error - Uncaught TypeError: Cannot instantiate an arrow function

**URL:** <https://forum.elixirforum.com/t/absinthe-socket-js-error-uncaught-typeerror-cannot-instantiate-an-arrow-function/41874>\
**Category:** Questions\
**Tags:** phoenix, javascript, absinthe\
**Created:** [August 24, 2021, 7:47am UTC](https://forum.elixirforum.com/t/absinthe-socket-js-error-uncaught-typeerror-cannot-instantiate-an-arrow-function/41874 "2021-08-24T07:47:50Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hermanverschooten](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/hermanverschooten/32/6447_2.png) [@Hermanverschooten](https://forum.elixirforum.com/u/Hermanverschooten)\
**Post date:** [August 24, 2021, 7:47am UTC](https://forum.elixirforum.com/t/absinthe-socket-js-error-uncaught-typeerror-cannot-instantiate-an-arrow-function/41874/1 "2021-08-24T07:47:50Z")

</div>

I have been using absinthe for a while now, and a couple of months ago we switched from webpack to parcel for our JS bundling. All worked fine for some time, until recently I was notified by one of our clients that the site was no longer working, the wheel kept spinning. I investigated and found a JS error on calling `AbsintheSocket.create` was logged. The odd thing was that at first, the page still worked in dev, but after an upgrade of some npm stuff, it gave the same error. Initially my guess was something in parcel was causing this and as I had learned that phoenix 1.6 will prefer `esbuild`. I branched and tried that only to find that the same error still occurs.  
Wanting to make sure it is not something else in my code that triggers this error, I cloned the phx\_esbuild\_demo repo that @josevalim was kind enough to provide. I added the `@absinthe/socket` npm package, imported it in `js/app.js`, and it triggers the same error.  
I pushed the repo to github ([GitHub - Hermanverschooten/phx\_esbuild\_demo: Test for absinthe socket · GitHub](https://github.com/Hermanverschooten/phx_esbuild_demo), branch test\_absinthe).  
Has anyone else run into this error and found a solution? The only reference I find googling has to do with `shadow-cljs`, but I do not see any solution there.

---

<div class="post-metadata">

**Author:** ![Hermanverschooten](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/hermanverschooten/32/6447_2.png) [@Hermanverschooten](https://forum.elixirforum.com/u/Hermanverschooten)\
**Post date:** [August 24, 2021, 8:36am UTC](https://forum.elixirforum.com/t/absinthe-socket-js-error-uncaught-typeerror-cannot-instantiate-an-arrow-function/41874/2 "2021-08-24T08:36:49Z")

</div>

In the mean time I found that replacing

```elixir
import * as AbsintheSocket from '@absinthe/socket';

```

with

```elixir
const AbsintheSocket = require '@absinthe/socket';

```

seems to work with `esbuild` but sadly not with `parcel v2.0.0-rc.0`.

---

<div class="post-metadata">

**Author:** ![maartenvanvliet](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/maartenvanvliet/32/18801_2.png) [@maartenvanvliet](https://forum.elixirforum.com/u/maartenvanvliet)\
**Post date:** [August 28, 2021, 6:31am UTC](https://forum.elixirforum.com/t/absinthe-socket-js-error-uncaught-typeerror-cannot-instantiate-an-arrow-function/41874/3 "2021-08-28T06:31:52Z")

</div>

The phx\_esbuild\_repo you link to is empty.

---

<div class="post-metadata">

**Author:** ![Hermanverschooten](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/hermanverschooten/32/6447_2.png) [@Hermanverschooten](https://forum.elixirforum.com/u/Hermanverschooten)\
**Post date:** [August 29, 2021, 8:12am UTC](https://forum.elixirforum.com/t/absinthe-socket-js-error-uncaught-typeerror-cannot-instantiate-an-arrow-function/41874/4 "2021-08-29T08:12:06Z")

</div>

Oops, code is there now.

---

<div class="post-metadata">

**Author:** ![mogelbrod](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mogelbrod/32/24475_2.png) [@mogelbrod](https://forum.elixirforum.com/u/mogelbrod)\
**Post date:** [October 6, 2021, 11:55am UTC](https://forum.elixirforum.com/t/absinthe-socket-js-error-uncaught-typeerror-cannot-instantiate-an-arrow-function/41874/5 "2021-10-06T11:55:40Z")

</div>

Having the same problem using `parcel@2.0.0-rc.0`:

```elixir
Uncaught (in promise) TypeError: Cannot instantiate an arrow function
    at Object._newArrowCheck [as default] (newArrowCheck.js:7)
    at create1 (create.js:82) - 

```

The shadow-cljs thread I believe @Hermanverschooten referred to: [https://clojurians-log.clojureverse.org/shadow-cljs/2018-08-10](https://clojurians-log.clojureverse.org/shadow-cljs/2018-08-10)  
Related github issue: [Runtime Error - Cannot instantiate an arrow function · Issue #365 · thheller/shadow-cljs · GitHub](https://github.com/thheller/shadow-cljs/issues/365)

---

<div class="post-metadata">

**Author:** ![Hermanverschooten](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/hermanverschooten/32/6447_2.png) [@Hermanverschooten](https://forum.elixirforum.com/u/Hermanverschooten)\
**Post date:** [October 6, 2021, 1:42pm UTC](https://forum.elixirforum.com/t/absinthe-socket-js-error-uncaught-typeerror-cannot-instantiate-an-arrow-function/41874/6 "2021-10-06T13:42:25Z")

</div>

This problem is keeping me from upgrading to Phoenix 1.6. With `require` instead of `import` it works for `esbuild` with phx 1.5, but no longer with 1.6. I tried contacting the original creator of absinthe\_socket through slack, but to no avail. And my JS knowledge is not good enough to rewrite.

---

<div class="post-metadata">

**Author:** ![Hermanverschooten](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/hermanverschooten/32/6447_2.png) [@Hermanverschooten](https://forum.elixirforum.com/u/Hermanverschooten)\
**Post date:** [November 7, 2021, 10:37am UTC](https://forum.elixirforum.com/t/absinthe-socket-js-error-uncaught-typeerror-cannot-instantiate-an-arrow-function/41874/7 "2021-11-07T10:37:44Z")

</div>

Just for information, the `require` form now works with phoenix as of 1.6.2 😀

---

<div class="post-metadata">

**Author:** ![neurodynamic](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/n/6de8d8/32.png) [@neurodynamic](https://forum.elixirforum.com/u/neurodynamic)\
**Post date:** [January 11, 2022, 6:03pm UTC](https://forum.elixirforum.com/t/absinthe-socket-js-error-uncaught-typeerror-cannot-instantiate-an-arrow-function/41874/8 "2022-01-11T18:03:49Z")

</div>

I had the `require` fix working for a while with `esbuild`, but for unrelated reasons I recently started using [esbuild’s inject feature](https://esbuild.github.io/api/#inject) and that has brought the `Uncaught TypeError: Cannot instantiate an arrow function` issue with `@absinthe/socket` back. When I use the `inject` option, I see the error, and when I take it out, everything’s fine.

Assuming it was an issue with using arrow function syntax, I even rewrote the `@absinthe/socket` library and published a version without arrow syntax under `@absinthe-noarrows/socket` but that doesn’t seem to fix the problem either. I’m completely at a loss. It seems like I either need to find a way to replace `process.cwd()` without using `inject` (which is needed for `path-browserify`), or I can’t use `@absinthe/socket`.

Anyone have any idea:

1. How to fix this?
2. Why using `inject` would cause it?
3. Why getting rid of all of the arrow functions in the `@absinthe/socket` code wouldn’t fix it?

---

<div class="post-metadata">

**Author:** ![hubertlepicki](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/hubertlepicki/32/6822_2.png) [@hubertlepicki](https://forum.elixirforum.com/u/hubertlepicki)\
**Post date:** [November 28, 2023, 5:31pm UTC](https://forum.elixirforum.com/t/absinthe-socket-js-error-uncaught-typeerror-cannot-instantiate-an-arrow-function/41874/9 "2023-11-28T17:31:12Z")

</div>

@neurodynamic do you remember fixing the issue by any chance? I am stuck on the same error too

---

<div class="post-metadata">

**Author:** ![neurodynamic](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/n/6de8d8/32.png) [@neurodynamic](https://forum.elixirforum.com/u/neurodynamic)\
**Post date:** [November 28, 2023, 9:43pm UTC](https://forum.elixirforum.com/t/absinthe-socket-js-error-uncaught-typeerror-cannot-instantiate-an-arrow-function/41874/10 "2023-11-28T21:43:22Z")

</div>

Looking back through my commits, it looks like I eventually just gave up on using the inject feature. Sorry I don’t have better news!

---

<div class="post-metadata">

**Author:** ![hubertlepicki](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/hubertlepicki/32/6822_2.png) [@hubertlepicki](https://forum.elixirforum.com/u/hubertlepicki)\
**Post date:** [November 29, 2023, 7:10am UTC](https://forum.elixirforum.com/t/absinthe-socket-js-error-uncaught-typeerror-cannot-instantiate-an-arrow-function/41874/11 "2023-11-29T07:10:09Z")

</div>

okay thanks.

I have decided to update the dependencies and migrate to graphql-ws which should work as a drop-in replacement: [GraphQLWsLink - Apollo GraphQL Docs](https://www.apollographql.com/docs/react/api/link/apollo-link-subscriptions)

Keep your fingers crossed ;D

---

<div class="post-metadata">

**Author:** ![hubertlepicki](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/hubertlepicki/32/6822_2.png) [@hubertlepicki](https://forum.elixirforum.com/u/hubertlepicki)\
**Post date:** [November 29, 2023, 3:19pm UTC](https://forum.elixirforum.com/t/absinthe-socket-js-error-uncaught-typeerror-cannot-instantiate-an-arrow-function/41874/12 "2023-11-29T15:19:18Z")

</div>

so in the end I keep using the @absinthe libs, the trick with replacing “import” with “require” actually seems to work for me

---

<div class="post-metadata">

**Author:** ![cinoss](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/cinoss/32/13983_2.png) [@cinoss](https://forum.elixirforum.com/u/cinoss)\
**Post date:** [October 18, 2024, 4:53pm UTC](https://forum.elixirforum.com/t/absinthe-socket-js-error-uncaught-typeerror-cannot-instantiate-an-arrow-function/41874/13 "2024-10-18T16:53:55Z")

</div>

I am doing patch use all the package from `src` instead of `dist` as the build seems a bit outdated.

> <https://gist.github.com/cinoss/df65833fe0e7a38f51c1170979011cf8>
