0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

React起動時の「ERR_OSSL_EVP_UNSUPPORTED」エラーの解決法

Posted at

React プロジェクトを Node.js v18 環境で立ち上げようとしたとき、以下のようなエラーが発生することがあります。

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:69:19)
    ...
code: 'ERR_OSSL_EVP_UNSUPPORTED'

これは Webpack などのビルドツールが OpenSSL 3 に対応していないことが原因で、Node.js v17以降でよく見られる問題です。本記事ではその解決策を紹介します。

💡 原因

Node.js v17 以降、OpenSSL 3 が標準で使用されるようになりました。
一部のパッケージ(特に webpack@4 などの古いバージョン)は OpenSSL 3 に対応しておらず、ハッシュ生成などの処理が失敗します。

✅ 解決方法

方法1:環境変数 NODE_OPTIONS を使って起動(簡易)

Mac や Linux の場合:

NODE_OPTIONS=--openssl-legacy-provider npm start

Windows の場合(PowerShell):

$env:NODE_OPTIONS="--openssl-legacy-provider"
npm start

Windows の場合(cmd):

set NODE_OPTIONS=--openssl-legacy-provider
npm start

方法2:package.json のスクリプトに組み込む(恒久対応)

"scripts": {
  "start": "NODE_OPTIONS=--openssl-legacy-provider react-scripts start",
  "build": "NODE_OPTIONS=--openssl-legacy-provider react-scripts build"
}

Windows 環境では cross-env を使うのがおすすめ

npm install --save-dev cross-env
"scripts": {
  "start": "cross-env NODE_OPTIONS=--openssl-legacy-provider react-scripts start"
}

方法3:Node.js のバージョンを下げる(根本的)

OpenSSL 3 による問題を完全に避けたい場合は、Node.js v16 など LTS 安定版を使用するのも手です。

nvm を使ってバージョンを変更

nvm install 16
nvm use 16

📝 まとめ

対応方法 手軽さ 推奨度
環境変数を一時的に設定
package.json に設定
Node.js のバージョンを変更

Node.js のバージョンアップにより思わぬところでエラーが出ることもありますが、今回のように環境変数で対処できるケースも多いです。
同じエラーで困っている方の助けになれば幸いです!

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?