2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

SyntaxError: The requested module 'node:util' does not provide an export named 'styleText'エラーが出る

2
Last updated at Posted at 2026-04-13

はじめに

MacでReact+Viteの環境構築を行っていた際に、プロジェクト作成コマンドを実行したところでエラーが発生しました。原因と解決策を記録として残します。

問題

Viteプロジェクトを作成しようとした際、以下のエラーが発生して中断されました。

実行コマンド

npm create vite@latest

エラー内容

Need to install the following packages:
  create-vite@9.0.4
Ok to proceed? (y) y
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'create-vite@9.0.4',
npm WARN EBADENGINE   required: { node: '^20.19.0 || >=22.12.0' },
npm WARN EBADENGINE   current: { node: 'v18.16.0', npm: '9.5.1' }
npm WARN EBADENGINE }
file:///Users/takahiro/.npm/_npx/1415fee72ff6294b/node_modules/create-vite/dist/index.js:1
                                                                                                                                                                       ^^^^^^^^^
SyntaxError: The requested module 'node:util' does not provide an export named 'styleText'
    at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:190:5)

Node.js v18.16.0
npm notice 
npm notice New major version of npm available! 9.5.1 -> 11.12.1
npm notice Changelog: https://github.com/npm/cli/releases/tag/v11.12.1
npm notice Run npm install -g npm@11.12.1 to update!
npm notice 
npm ERR! code 1
npm ERR! path /Applications/github
npm ERR! command failed
npm ERR! command sh -c create-vite

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/takahiro/.npm/_logs/2026-04-12T12_22_32_680Z-debug-0.log

原因
エラーメッセージにある通り、Node.jsのバージョンが古いことが原因でした。
最新の create-vite (v9.0.4) は Node.js v20.19.0 以上、または v22.12.0 以上を要求していますが、実行環境が v18.16.0 だったため、必要なモジュール(styleText)を読み込めず構文エラーが発生していました。

解決方法

nodenv を使用して、Node.js のバージョンを最新の推奨版(LTS)へアップデートすることで解決しました。

1. 新しいバージョンのインストール
現在の安定版である v22.12.0 をインストールします。

nodenv install 22.12.0

2. バージョンの切り替え
インストールしたバージョンを全体(global)に適用し、設定を反映させます。

nodenv global 22.12.0
source ~/.zshrc
nodenv rehash

3. 確認
Node.js のバージョンが正しく更新されたか確認します。

node -v
# v22.12.0 と表示されればOK

4. プロジェクトの再作成
改めて Vite プロジェクトを作成します。

npm create vite@latest

今度はエラーが出ることなく、正常にプロジェクトが作成されました。

おわりに

フロントエンドのツールチェイン(Viteなど)は進化が早いため、Node.js のバージョンも定期的に見直す必要があると再認識しました。
もし同様のエラーが出た場合は、まず node -vで自身の環境を確認してみることをおすすめします。

参考

・nodenv GitHub リポジトリ
https://github.com/nodenv/nodenv

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?