💨

Vercel上のNuxt.jsで`Could not load Nuxt configuration.` が出た

2021/09/27に公開

起きたこと

UniversalモードのNuxt.jsアプリをVercelにデプロイし、ページを開くとエラーが出る。
functionのログを見ると以下のログが残っていた。

[GET] /
13:10:38:35
2021-09-25T04:10:38.643Z	undefined	ERROR	Uncaught Exception 	{"errorType":"Error","errorMessage":"Could not load Nuxt configuration. Make sure all dependencies are listed in package.json dependencies or in serverFiles within builder options:\n Error: Cannot find module 'esm'\nRequire stack:\n- /var/task/vercel__launcher.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js","stack":["Error: Could not load Nuxt configuration. Make sure all dependencies are listed in package.json dependencies or in serverFiles within builder options:"," Error: Cannot find module 'esm'","Require stack:","- /var/task/vercel__launcher.js","- /var/runtime/UserFunction.js","- /var/runtime/index.js","    at Object.<anonymous> (/var/task/vercel__launcher.js:23:13)","    at Module._compile (internal/modules/cjs/loader.js:1072:14)","    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)","    at Module.load (internal/modules/cjs/loader.js:937:32)","    at Function.Module._load (internal/modules/cjs/loader.js:778:12)","    at Module.require (internal/modules/cjs/loader.js:961:19)","    at require (internal/modules/cjs/helpers.js:92:18)","    at _tryRequire (/var/runtime/UserFunction.js:75:12)","    at _loadUserApp (/var/runtime/UserFunction.js:95:12)","    at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)"]}
Unknown application error occurred
Error

Error: Cannot find module 'esm' とのこと 🤔

前提

{
  "builds": [
    {
      "src": "nuxt.config.js",
      "use": "@nuxtjs/vercel-builder",
      "config": {}
    }
  ]
}

原因

nuxt.config.ts で読み込んでいるライブラリがdevDependenciesに入っていたことが原因でした。今回はsassとsass-loader
devDependenciesからdependenciesに移動して解決
同様の事例: https://github.com/nuxt/vercel-builder/issues/545#issuecomment-821868398

感想

nuxt@2.15からESM記法のruntime engineをesmからjitiに移行したためそのせいか?と思ったりして詰まりましたが、利用側の問題でした。これは反省
とはいえbuild時に気づければ良さそうなんだけど、どうするのがいいか…

GitHubで編集を提案

Discussion