Next.js の Deno Deploy 移行

なぜか Found 0 assets
.next なら大丈夫
deployctl deploy --include=".next/standalone" --project=kamekyame-portfolio-8 --dry-run .\.next\standalone\server.js
i Using config file 'D:\portfolio\deno.json'
i Performing dry run of deployment
‼ Failed to get token from credentials file. Will provision a new token for this execution but please make sure to fix the issue afterwards.
× The credentials file has been tampered with and will be ignored. Please delete it.
i Provisioning a new access token...
i Authorization URL: https://dash.deno.com/signin/cli?claim_challenge=xxx
√ Token obtained successfully
√ Deploying to project kamekyame-portfolio-8.
√ Entrypoint: D:\portfolio\.next\standalone\server.js
i Uploading all files from the current dir (D:\portfolio)
√ Found 0 assets.
√ No new assets to upload.

windows の問題なのか…
deployctl で毎回認証求められるのも

.next フォルダごとアップロードするとこうなる
windows でビルドした問題なのかもしれない
error: The deployment failed: content of 'file:///src/.next/static/media/qiita.eae2a418.png' module is not valid utf8

↑のはおそらくWindowsだから
create-next-app から作ったプロジェクトを deployctl で上げようとしてもダメだった
wsl インストールして確かめる

nextjs 公式? の deploy 方法
standalone の server.cjs を実行する方法と
@deno/nextjs-start を使う方法が載っている

wsl でやったら とりあえず Found 193 assets。 よかった

wsl で create-next-app, @deno/nextjs-start でやってもこれ
error: The deployment failed: content of 'file:///src/.next/static/media/4473ecc91f70f139-s.p.woff' module is not valid utf8

mac だとさすがに↑のはうまくいったから Windows、Linux の問題かも…

mac でもダメだった。app router がだめかも知れない
とおもったら pages router でもだめ

以前 mac でうまくデプロイできたはずなのに再現できない…
pages router でも app router でも @deno/nextjs-start 使ったものでも standalone の server.cjs 実行するのもうまくいかない 🤔
全部↓ので Deployment failed になる
module is not valid utf8

変なことせずに、このブログに沿ってリポジトリフォーク→Deno deploy 連携してみたけどダメっぽい
まだ別のエラー
どうも、js じゃないファイルを js として上げようとしてたりするのかなぁ…
Error: The deployment failed: Error parsing 'file:///src/.next/server/pages/404.html': Expected ';', '}' or <eof> at file:///src/.next/server/pages/404.html:1:11
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta name="viewport...
~~~~

どうも .next/standalone のなかに package.json があるのがダメっぽい
これがあると js,json 以外アップロードするとエラーになる

pacage.json けしてデプロイしたらやっと見たいエラーにたどり着けた(以前見たエラーになった)
これを再現したくていままで遠回りをしていた。どこかで Deno Deploy のアプデがあったのかもしれない
そして、これはたぶん node_modules が上がっていないことが原因だと思う
deployctl はデフォルトで node_modules を上げないらしい
error: The deployment failed: UNCAUGHT_EXCEPTION
Error: Cannot find module 'next'
Require stack:
- /src/.next/standalone/server.cjs
at Function.Module._resolveFilename (node:module:617:15)
at Function.Module._load (node:module:495:27)
at Module.require (node:module:679:19)
at require (node:module:810:16)
at Object.<anonymous> (file:///src/.next/standalone/server.cjs:16:1)
at Object.<anonymous> (file:///src/.next/standalone/server.cjs:39:4)
at Module._compile (node:module:743:34)
at Object.loadCjs [as .cjs] (node:module:772:10)
at Module.load (node:module:660:32)
at Function.Module._load (node:module:532:12)

--include に node_modules を明記して
一度は全部アップロードしてそうだったけど何回かしている間に明示的に指定してもアップロードされなくなってしまった なんでだろう

nextjs-start を手元で実行すると
$ deno run -A jsr:@deno/nextjs-start
⨯ Failed to start server
PermissionDenied: Permission denied (os error 13)
at listen (ext:deno_net/01_net.js:504:35)
at serve (ext:deno_http/00_serve.ts:565:16)
at ServerImpl._serve (node:http:1460:22)
at node:http:1405:23
at Array.processTicksAndRejections (ext:deno_node/_next_tick.ts:28:11)
at eventLoopTick (ext:core/01_core.js:174:29) {
name: "PermissionDenied",
code: "EACCES"
}

同じ現象(package.json があるとhtmlとかがアップできない問題)にあって
このスクラップを見つけてくれた人がいて、 Issue 化してくれた。
直っているかもしれない

再度やってみたらこれ。いろいろ手元をいじっていたので、もう一度最初からやり直してみる
Error The deployment failed: content of 'file:///src/.next/static/media/4473ecc91f70f139-s.p.woff' module is not valid utf8