前提
Gitlab PagesにNuxt.jsで生成した静的ページをホスティングしているのですが、
Nuxt.jsのバージョンを上げたところ、nuxt generate
の実行に失敗するようになりました。
環境
- node.js 10.15.3
- yarn 1.16.0
- nuxt.js 2.1.0 -> 2.8.0
現象
% yarn run generate
yarn run v1.16.0
$ nuxt generate
ℹ Preparing project for development
ℹ Initial build may take a while
✔ Builder initialized
✔ Nuxt files generated
✔ Client
Compiled successfully in 6.76s
✔ Server
Compiled successfully in 5.56s
ℹ Waiting for file changes
FATAL ENOENT: no such file or directory, stat '/home/epaew/workspace/nuxt_app/.nuxt/dist/client'
╭─────────────────────────────────────────────────────────────╮
│ │
│ ✖ Nuxt Fatal Error │
│ │
│ Error: ENOENT: no such file or directory, stat │
│ '/home/epaew/workspace/nuxt_app/.nuxt/dist/client' │
│ │
╰─────────────────────────────────────────────────────────────╯
error Command failed with exit code 1.
解決策
GitHub に issue が上がっていました
https://github.com/nuxt/nuxt.js/issues/5840#issuecomment-497521402
Solution: You are mixing cjs with es syntax for nuxt.config. Simply using export default fixes issue.
nuxt.config.js を以下の通り修正
-module.exports = {
+export default {
古い Nuxt で create-nuxt-app
した場合、 nuxt.config.js
あたりに CommonJS の記法が残ってしまっているみたいです。