ノードをアップグレードし、既存のファイルを構築しました。
しかし、ビルドされず、エラーが発生しました。
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: │
│ ~~/nuxt.config.js │
│ require() of ES modules is not supported. │
│ require() of ~~/nuxt.config.js from │
│ ~~/config.js is an ES │
│ module file as it is a .js file whose nearest parent package.json contains "type": │
│ "module" which defines all .js files in that package scope as ES modules. │
│ Instead rename nuxt.config.js to end in .cjs, change the requiring code to use │
│ import(), or remove "type": "module" from │
│ ~~/package.json.
そこで、package.json ファイルから 'type: module' を削除しました。
削除しても大丈夫ですか?
ベストアンサー1
"type": "module"
ファイルにがある場合はpackage.json
、ソースコードでimport
構文を使用する必要があります。 がない場合は、require
構文を使用する必要があります。つまり、 を追加する"type": "module"
とpackage.json
ES 6 モジュールが有効になります。詳細については、ここ。