How to import GUN SEA with Deno Fresh?

Viewed 21

The first attempt to import GUN from Fresh was to add the gun library from esm to import_map.json, where it correctly works in simple examples of using GUN.

{
  "imports": {
    ...
    "gun": "https://esm.sh/gun@0.2020.1237",
  }
}

But the problem occurred when I wanted to import additionally gun/sea, After importing import Sea from "gun/sea";.

I got this error:

error: Uncaught (in promise) Error: Dynamic require of "./lib/text-encoding" is not supported

On GitHub I read to import gun/lib/mobile before importing SEA when such a problem occurs. But this brings an additional problem:

error: Uncaught (in promise) TypeError: Assignment to constant variable.

I checked the gun/lib/mobile file and it literally contains a few lines of global variables:

import Buffer from "buffer";
import { TextEncoder, TextDecoder } from "text-encoding";
global.Buffer = global.Buffer || Buffer.Buffer;
global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;

Is there any chance to make SEA work on Fresh?

0 Answers
Related