Skip to content

Commit b9beef1

Browse files
authored
Merge pull request #82 from PetrIvan/fix/pages-disable-config-injection
fix: stop configure-pages from injecting a config that breaks export
2 parents 6d42ba9 + f2c331f commit b9beef1

3 files changed

Lines changed: 19 additions & 40 deletions

File tree

.github/workflows/nextjs.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ jobs:
5454
node-version: "22"
5555
cache: ${{ steps.detect-package-manager.outputs.manager }}
5656
- name: Setup Pages
57+
# Deliberately no `static_site_generator: next`. That option makes
58+
# configure-pages write a ./next.config.js, which it cannot do for our
59+
# next.config.ts, so it drops a minimal JS config that Next 16 loads in
60+
# preference to ours. That injected config lacks `output: "export"`, so
61+
# the static site is never written to out/ and the build fails at the
62+
# postbuild copy step. Our next.config.ts already sets output: "export"
63+
# and images.unoptimized, and the site is served from a root custom
64+
# domain, so no basePath injection is needed.
5765
uses: actions/configure-pages@v4
58-
with:
59-
# Automatically inject basePath in your Next.js configuration file and disable
60-
# server side image optimization (https://nextjs.org/docs/api-reference/next/image#unoptimized).
61-
#
62-
# You may remove this line if you want to manage the configuration yourself.
63-
static_site_generator: next
6466
- name: Restore cache
6567
uses: actions/cache@v3
6668
with:

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
# next.js
1313
/.next/
1414
/out/
15+
# Guard against a stray next.config.js: Next 16 loads it in preference to our
16+
# next.config.ts, silently dropping output: "export" (see .github/workflows/nextjs.yml).
17+
/next.config.js
1518

1619
# onnxruntime-web wasm binaries (generated from node_modules by scripts/copy-ort-wasm.mjs)
1720
/public/wasm/

scripts/copy-sw.mjs

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,22 @@
44
// that header, so a worker at /serwist/sw.js would be capped to /serwist/ scope
55
// and never control the app. Copying it to the site root makes its default
66
// scope `/` with no header required, which is what static hosting needs.
7-
import { copyFileSync, existsSync, readdirSync } from "node:fs";
7+
import { copyFileSync, existsSync } from "node:fs";
88

9-
// `next build` with `output: "export"` is meant to write the route handler
10-
// output to out/serwist/sw.js, but that export step is unreliable across
11-
// platforms: it lands on disk locally (Windows) yet is silently missing in CI
12-
// (Linux), with the same Next and Node versions. The compiled body is always
13-
// written to .next/server/app/serwist/<param>.body during the build, before and
14-
// independent of the export phase, and is byte-identical to the exported file.
15-
// Fall back to it so the root copy is produced in either environment.
16-
function firstExisting(candidates) {
17-
return candidates.find((p) => existsSync(p));
18-
}
19-
20-
const swSrc = firstExisting([
21-
"out/serwist/sw.js",
22-
".next/server/app/serwist/sw.js.body",
23-
]);
24-
25-
if (!swSrc) {
26-
console.error("[copy-sw] service worker not found - did 'next build' run?");
27-
for (const dir of ["out/serwist", ".next/server/app/serwist"]) {
28-
if (existsSync(dir)) {
29-
console.error(`[copy-sw] ${dir}: ${readdirSync(dir).join(", ")}`);
30-
}
31-
}
9+
const src = "out/serwist/sw.js";
10+
if (!existsSync(src)) {
11+
console.error(`[copy-sw] ${src} not found - did 'next build' export to out/?`);
3212
process.exit(1);
3313
}
3414

35-
copyFileSync(swSrc, "out/sw.js");
36-
console.log(`[copy-sw] ${swSrc} -> out/sw.js`);
15+
copyFileSync(src, "out/sw.js");
16+
console.log(`[copy-sw] ${src} -> out/sw.js`);
3717

3818
// The worker ends with sourceMappingURL=sw.js.map, which resolves to /sw.js.map
3919
// once served from the root, so copy the map alongside it to avoid a 404. A
4020
// missing map is not fatal - it only affects debugging.
41-
const mapSrc = firstExisting([
42-
"out/serwist/sw.js.map",
43-
".next/server/app/serwist/sw.js.map.body",
44-
]);
45-
46-
if (mapSrc) {
21+
const mapSrc = "out/serwist/sw.js.map";
22+
if (existsSync(mapSrc)) {
4723
copyFileSync(mapSrc, "out/sw.js.map");
4824
console.log(`[copy-sw] ${mapSrc} -> out/sw.js.map`);
49-
} else {
50-
console.warn("[copy-sw] sw.js.map not found, skipping (non-fatal)");
5125
}

0 commit comments

Comments
 (0)