11
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

firebaseのstorageでXMLHttpRequestエラーの対処法(ReferenceError: XMLHttpRequest is not defined)

Posted at

はじめに

firebaseのCloudStorageNextで使おうとしたら次のようなエラーが起きた。

C:\XXXXXXXXXXXXXX\node_modules\@firebase\storage\dist\index.cjs.js:611
        this.xhr_ = new XMLHttpRequest();
                        ^

ReferenceError: XMLHttpRequest is not defined

原因

どうやらXMLHttpRequestはブラウザ用のAPIらしく、要はクライアントサイドでしか呼び出せないみたい。

対処法

Next.jsであれば、getInitialProps()内でstorageを呼び出すのではなく、useEffect()等を使ってクライアントサイドで呼び出す。

Node.jsには代替としてHttp APIがあるみたい(確かめていません)
詳しくはこちらの記事を参考にしてください。
Qiita - Node.jsでFetch APIを使うと XMLHttpRequest is not defined になる @IzumiSy

参考

11
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?