Cloudflareにbunを使ってデプロイしようとしたら Error: Cannot find module '/opt/buildhome/repo/build' のエラーが出たメモ

# 概要
Cloudflareへのデプロイに失敗した。
具体的に何が悪いのかがわかりにくかったのでメモ。
結論から言うと、ローカルでは動く`bunx run build`が問題だった。
ビルドコマンドとして`npm run build`を指定したところ解決。

[この時点のソース](https://github.com/hibohiboo/odyssage/tree/a274e986ab9efd09280574f9581ea11b2b26d423)

**2024.11.11 追記**
`bun run build` をビルドコマンドにしてもエラーは出なかった。


# 発生したエラー

```
01:13:57.763	Starting: build
01:13:57.788	node:internal/modules/cjs/loader:1252
01:13:57.788	  throw err;
01:13:57.788	  ^
01:13:57.789	
01:13:57.789	Error: Cannot find module '/opt/buildhome/repo/build'
01:13:57.789	    at Function._resolveFilename (node:internal/modules/cjs/loader:1249:15)
01:13:57.789	    at Function._load (node:internal/modules/cjs/loader:1075:27)
01:13:57.789	    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
01:13:57.789	    at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)
01:13:57.789	    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:170:5)
01:13:57.789	    at node:internal/main/run_main_module:36:49 {
01:13:57.789	  code: 'MODULE_NOT_FOUND',
01:13:57.789	  requireStack: []
01:13:57.789	}
```


<details><summary>全文</summary><div>

```
01:13:43.741	Cloning repository...
01:13:44.413	From https://github.com/hibohiboo/odyssage
01:13:44.413	 * branch            03bc0165055f987216652bd15e34776fa9cdde1c -> FETCH_HEAD
01:13:44.414	
01:13:44.454	HEAD is now at 03bc016 fix test
01:13:44.454	
01:13:44.543	
01:13:44.543	Using v2 root directory strategy
01:13:44.570	Success: Finished cloning repository files
01:13:46.209	Checking for configuration in a wrangler.toml configuration file (BETA)
01:13:46.210	
01:13:46.309	No wrangler.toml file found. Continuing.
01:13:47.037	Detected the following tools from environment: nodejs@22.11.0, bun@1.1.34
01:13:47.037	Installing nodejs 22.11.0
01:13:47.483	Trying to update node-build... ok
01:13:47.581	To follow progress, use 'tail -f /tmp/node-build.20241110161347.553.log' or pass --verbose
01:13:47.694	Downloading node-v22.11.0-linux-x64.tar.gz...
01:13:47.970	-> https://nodejs.org/dist/v22.11.0/node-v22.11.0-linux-x64.tar.gz
01:13:50.031	Installing node-v22.11.0-linux-x64...
01:13:50.476	Installed node-v22.11.0-linux-x64 to /opt/buildhome/.asdf/installs/nodejs/22.11.0
01:13:50.477	
01:13:51.554	Installing bun 1.1.34
01:13:51.688	Downloading Bun v1.1.34...
01:13:52.634	Archive:  /tmp/asdf-bun.ogZ7/bun.zip
01:13:53.397	  inflating: /opt/buildhome/.asdf/downloads/bun/1.1.34/bun  
01:13:53.460	Installing Bun v1.1.34...
01:13:53.556	Bun v1.1.34 is installed successfully!
01:13:54.053	Installing project dependencies: bun install --frozen-lockfile
01:13:54.281	bun install v1.1.34 (5e5e7c60)
01:13:54.285	Resolving dependencies
01:13:54.694	Resolved, downloaded and extracted [14]
01:13:56.671	
01:13:56.671	+ prettier@3.3.3
01:13:56.672	+ turbo@2.2.3
01:13:56.672	
01:13:56.672	527 packages installed [2.39s]
01:13:56.689	Executing user command: bunx run build
01:13:56.961	Resolving dependencies
01:13:57.419	Resolved, downloaded and extracted [10]
01:13:57.466	Saved lockfile
01:13:57.732	Watching /opt/buildhome/repo and all sub-directories not excluded by your .gitignore. Will not monitor dotfiles.
01:13:57.743	Found & ignored ./node_modules ; is listed in .gitignore
01:13:57.749	Found & ignored ./docs/astro/src/styles/index.css ; has ignored extension
01:13:57.749	Found & ignored ./docs/astro/src/styles/theme.css ; has ignored extension
01:13:57.749	Found & ignored ./packages/app/src/App.css ; has ignored extension
01:13:57.750	Found & ignored ./packages/app/src/index.css ; has ignored extension
01:13:57.763	
01:13:57.763	Starting: build
01:13:57.788	node:internal/modules/cjs/loader:1252
01:13:57.788	  throw err;
01:13:57.788	  ^
01:13:57.789	
01:13:57.789	Error: Cannot find module '/opt/buildhome/repo/build'
01:13:57.789	    at Function._resolveFilename (node:internal/modules/cjs/loader:1249:15)
01:13:57.789	    at Function._load (node:internal/modules/cjs/loader:1075:27)
01:13:57.789	    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
01:13:57.789	    at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)
01:13:57.789	    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:170:5)
01:13:57.789	    at node:internal/main/run_main_module:36:49 {
01:13:57.789	  code: 'MODULE_NOT_FOUND',
01:13:57.789	  requireStack: []
01:13:57.789	}
01:13:57.790	
01:13:57.790	Node.js v22.11.0
```

</div></details>

# デプロイに成功したときの設定

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/99876/ba74a8e5-eb1c-820d-0e65-8bac1aee951b.png)

# 参考

[【Cloudflare Pages】ブログを公開したい？...5分もあれば十分だ](https://zenn.dev/rivine/articles/2023-06-23-deploy-hugo-to-cloudflare-pages)  
[Cloudflare Pages Tools](https://developers.cloudflare.com/pages/configuration/build-image/#supported-languages-and-tools)  
[Cloudflare Pages](https://www.cloudflare.com/ja-jp/developer-platform/products/pages/)  
[cloudfrareでデプロイする](https://github.com/hibohiboo/odyssage/issues/3)