Open17

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 インストールして確かめる

すずともすずとも

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
すずともすずとも

https://deno.com/blog/nextjs-on-deno-deploy
変なことせずに、このブログに沿ってリポジトリフォーク→Deno deploy 連携してみたけどダメっぽい

まだ別のエラー
どうも、js じゃないファイルを js として上げようとしてたりするのかなぁ…
https://github.com/kamekyame/deploy-deno-test/actions/runs/13513085700/job/37756883768

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"
}
すずともすずとも

再度やってみたらこれ。いろいろ手元をいじっていたので、もう一度最初からやり直してみる

Error The deployment failed: content of 'file:///src/.next/static/media/4473ecc91f70f139-s.p.woff' module is not valid utf8