Yes using node.
Discussion
I'm going to guess you are missing a websocket-polyfill
I just literally copied your code without changing a thing and it just published nevent1qgspdq8u9akd245y7u5hxtthvcsjd4g54uzcrp7dnlx9ehxyfgyyj0cpzamhxue69uhhyetvv9ujumn0wd68ytnzv9hxgtcpz4mhxue69uhhyetvv9ujuerpd46hxtnfduhsqg9acv82a30e0v6lkhf05f7rmjzhaxnxa7v86y6asa2k6d7s6g4q5uu639fp
make sure to import "websocket-polyfill" if you are running a nodejs environment
Getting an errror from the import, even from a new project
pnpm install --save websocket-polyfill
```
import "websocket-polyfill"
```
npx esrun test.ts
```
/home/user/Documents/Programming/upload/node_modules/.pnpm/websocket-polyfill@1.0.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/websocket-polyfill/lib/index.js:8
(_a = (_b = global).WebSocket) !== null && _a !== void 0 ? _a : (_b.WebSocket = (0, import2_1.default)("ws"));
^
TypeError: (0 , import2_1.default) is not a function
at Object.
at Module._compile (node:internal/modules/cjs/loader:1369:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
at Module.load (node:internal/modules/cjs/loader:1206:32)
at Module._load (node:internal/modules/cjs/loader:1022:12)
at cjsLoader (node:internal/modules/esm/translators:366:17)
at ModuleWrap.
at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
at async ModuleLoader.eval (node:internal/modules/esm/loader:212:24)
at async loadESM (node:internal/process/esm_loader:28:7)
```
completely forgot about the websocket-polyfill, removed from the nostr-tools readme. Now recommends this:
``
import { useFetchImplementation } from 'nostr-tools/nip05'
useFetchImplementation(require('node-fetch'))
``
Adding that to ndk fixed it. Thanks!
```
import { useWebSocketImplementation } from 'nostr-tools/pool'
// or import { useWebSocketImplementation } from 'nostr-tools/relay' if you're using the Relay directly
import WebSocket from 'ws'
useWebSocketImplementation(WebSocket)
```
copied wrong snippet.