[bug] ReferenceError: `window` is not defined

オープン
#8 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
30/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
nodejs, typescript
領域
networking

調査の方向性

The detection logic is in getNativeWebSocket in src/utils.ts, which checks for a global WebSocket before falling back to the ws package. Reproduce by loading the package from a CommonJS Node script on a runtime without a global WebSocket, then trace where window is referenced. Done when that Node path resolves a WebSocket without a ReferenceError. The issue does not state a proposed fix, so confirm the expected behaviour with maintainers first.

索引モデルが issue の本文から書いたものです。

説明

Since I switched to recent versions of viem I am encountering this issue.

Possible related issue

I believe it is related to this https://github.com/wagmi-dev/viem/issues/1329.

Use case from which it comes
  • Essentially I am in a setup where my wagmi & viem code is in a common library.
  • This library is later imported in two different projects:
    - One using Node w/ CommonJS
    - One for the browser w/ ES modules
Error details

It seems that when in Node the method getNativeWebSockethere: https://github.com/wagmi-dev/isows/blob/5fd0ad1dd0f955383be002ae5d4a3b930dd4acb5/src/utils.ts#L3

does not detect global.WebSocket (while globalactually exists), meaning that for some reasons WebSocket was not imported before. Do we have to execute some specific commands to trigger the import of the ws npm module?

主要言語
TypeScript
スター
59
フォーク
7
平均マージ
53分
マージ済み PR(30日)
7

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

wevm/isows のほかの issue

wevm/isows の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。