Closed11

CI 上で `AssertionError [ERR_ASSERTION]: Rebuild triggered with no previous build available` エラー

9sako69sako6

結論

Dockerfile でマルチステージビルドしていたから


Versions

  • wrangler@3.55.0
  • @cloudflare/next-on-pages@1.11.2
  • next@14.2.3

問題

@cloudflare/next-on-pages でビルドした Next.js を CI 上で立ち上げる時に、たまに以下のエラーが発生する。CI ジョブのリトライで直ることがある。
頻発しててとても困ってるけど自分以外誰も困ってなさそう。なんか変なことしてるのかも。

立ち上げコマンドは以下。

Dockerfile
CMD ["wrangler", "pages", "dev", ".vercel/output/static", "--compatibility-flag=nodejs_compat", "--compatibility-date=2024-05-12", "--ip=0.0.0.0", "--port=3000"]

失敗時のログ

Attaching additional modules:
┌──────────────────────────────────────────────────────────────────────┬──────┬────────────┐
│ Name                                                                 │ Type │ Size       │
(略)
└──────────────────────────────────────────────────────────────────────┴──────┴────────────┘
✨ Compiled Worker successfully
 ⛅️ wrangler 3.55.0 (update available 3.63.2)
---------------------------------------------
[wrangler:inf] Ready on http://0.0.0.0:3000
[wrangler:inf] - http://127.0.0.1:3000
[wrangler:inf] - http://172.18.0.2:3000
AssertionError [ERR_ASSERTION]: Rebuild triggered with no previous build available
    at /usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:203709:42
    at se (/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:26157:43)
    at te (/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:26182:194)
    at Object.useState (/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:26497:18)
    at exports2.useState (/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:17600:19)
    at useEsbuild (/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:203685:59)
    at DevSession (/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:204068:20)
    at le (/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:26107:13)
    at Ve (/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:26629:14)
    at gh (/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:28833:102) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: undefined,
  expected: true,
  operator: '=='
}
Something went wrong:
AssertionError [ERR_ASSERTION]: Rebuild triggered with no previous build
available
    at /usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:203709:42
    at se (/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:26157:43)
    at te (/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:26182:194)
    at Object.useState
(/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:26497:18)
    at exports2.useState
(/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:17600:19)
    at useEsbuild
(/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:203685:59)
    at DevSession
(/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:204068:20)
    at le (/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:26107:13)
    at Ve (/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:26629:14)
    at gh (/usr/local/lib/node_modules/wrangler/wrangler-dist/cli.js:28833:102)

成功時のログ

Attaching additional modules:
┌──────────────────────────────────────────────────────────────────────┬──────┬────────────┐
│ Name                                                                 │ Type │ Size       │
├──────────────────────────────────────────────────────────────────────┼──────┼────────────┤
(略)
└──────────────────────────────────────────────────────────────────────┴──────┴────────────┘
✨ Compiled Worker successfully
 ⛅️ wrangler 3.55.0 (update available 3.63.2)
---------------------------------------------
⎔ Starting local server...
Parsed 1 valid header rule.
[wrangler-UserWorker:wrn] The latest compatibility date supported by the installed Cloudflare Workers Runtime is "2024-04-19",
but you've requested "2024-05-12". Falling back to "2024-04-19"...
Features enabled by your requested compatibility date may not be available.
Upgrade to `wrangler@3.63.2` to remove this warning.
⎔ Reloading local server...
Parsed 1 valid header rule.
[wrangler:inf] Ready on http://0.0.0.0:3000
[wrangler:inf] - http://127.0.0.1:3000
[wrangler:inf] - http://172.18.0.2:3000

9sako69sako6

previousBundle が存在しないけど updateBundle が呼ばれている状態。

async function updateBundle() {
    const newAdditionalModules = await getAdditionalModules();
    // nothing really changes here, so let's increment the id
    // to change the return object's identity
    setBundle((previousBundle) => {
        assert(
            previousBundle,
            "Rebuild triggered with no previous build available"
        );
        previousBundle.modules = dedupeModulesByName([
            ...(moduleCollector?.modules ?? []),
            ...newAdditionalModules,
        ]);
        return { ...previousBundle, id: previousBundle.id + 1 };
    });
}
9sako69sako6

中でビルドが実行されている。
そもそも npx @cloudflare/next-on-pages で既にビルド済みな気がするけど、どういうことだろう。わからなくなった。

9sako69sako6

--no-bundle をつけたら Web が立ち上がらなくなった。疎通確認で3分以上経過して諦めた図。

$ curl -I http://web:3000
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:03:30 --:--:--     0
9sako69sako6
---------------------------------------------
Your worker has access to the following bindings:
- Vars:
  - AUTH_SECRET: "(hidden)"
⎔ Starting local server...
Parsed 1 valid header rule.
⎔ Reloading local server...
Parsed 1 valid header rule.
[wrangler-UserWorker:wrn] The latest compatibility date supported by the installed Cloudflare Workers Runtime is "2024-04-19",
but you've requested "2024-05-12". Falling back to "2024-04-19"...
Features enabled by your requested compatibility date may not be available.
Upgrade to `wrangler@3.63.2` to remove this warning.
[wrangler:inf] Ready on http://0.0.0.0:3000
[wrangler:inf] - http://127.0.0.1:3000
[wrangler:inf] - http://172.18.0.2:3000
✘ [ERROR] service core:user:worker: Uncaught Error: No such module "wrangler:modules-watch".

    imported from "8nzco5odyz.js"[ERROR] MiniflareCoreError [ERR_RUNTIME_FAILURE]: The Workers runtime failed to start. There is likely additional logging output above.


✘ [ERROR] service core:user:worker: Uncaught Error: No such module "wrangler:modules-watch".

    imported from "8nzco5odyz.js"[ERROR] MiniflareCoreError [ERR_RUNTIME_FAILURE]: The Workers runtime failed to start. There is likely additional logging output above.

9sako69sako6

ファイルの変更を検知してるってことは、Dockerfile で npx @cloudflare/next-on-pages とランタイムを分けたマルチステージビルドしてるのは怪しいかも。

9sako69sako6

マルチステージビルドやめたら起きなくなった。経過観察する。

このスクラップは5ヶ月前にクローズされました