JavaScript 画像ファイルから EXIF を取得

技術情報
公開 2025年1月27日

画像ファイルから位置情報(EXIF)を取得する方法を Google 検索すると exif-js が上位にあがってきます。 しかし、exif-js を使用すると、以下のエラーメッセージが表示される時があります。

ReferenceError: n is not defined

https://github.com/exif-js/exif-js/issues/120
@mmase This happens when you use strict mode. It's been there since JS v5 (2009, thanks to Douglas Crockford :)). In strict mode you can not tnot declare a new variable without an explicit var. Probably some other bit of JavaScript has a "use strict"; in it, and then you use exif.

Plenty of other people have complained about this. But there are some other for loops that also don't have var yet. But I'll check the pull request.

strict mode を使用している JavaScript が一つでもあると発生するようです。
そのため、Reactの開発環境などでは exif-js を使用できません。
exif-js は 2017 年で開発が停止しており、この不具合が解消される見込みはありません。 exifr などの代わりのライブラリを使用しましょう。