🌀
【Nuxt.js】起動時「The CJS build of Vite's Node API is deprecated」のワーニングが発生
概要
nuxi devでNuxt.js起動時、表題の「The CJS build of Vite's Node API is deprecated」というワーニングが発生しました。特に動作に支障は無さそうですが、ちょっと内容が気になったので調べてみました。
前提
- 使用したNuxt.jsのバージョンは
3.12.4です。 - 使用したViteのバージョンは
5.4.0です。
原因など
Nuxt.jsのissueThe CJS build of Vite's Node API is deprecatedにも挙がっていました。
その中でリンクされているissueを追っていくとThis is because jiti (which we use to transpile the nuxt.config in c12 is loading the file in a CJS context.というコメントがあり、nuxt.configを読み込むライブラリが原因っぽいです。そしてこちらのコメントにある通り、jitiがv2に更新されれば解消される見込みだが、それまではenvの設定でワーニング非表示にするという対応が挙げられてます。2024年8月時点では、まだjitiのv2はベータ版っぽいです。
ちなみにViteのCJS buildがdeprecatedになったのはThe CJS build of Vite's Node API is deprecatedのstackoverflowの記事にある通り、Vite5からだそうです。
Discussion