Skip to content

Commit ba2ab2f

Browse files
authored
templates: fix experimental-build-mode compile generating invalid code (#13828)
When using `pnpm next build --experimental-build-mode compile` in our website template, Next.js outputs the following code: <img width="2322" height="1262" alt="Screenshot 2025-09-16 at 14 39 31@2x" src="https://github.com/user-attachments/assets/bb7dc5c1-ffe7-4ee7-8864-19cb2147c07d" /> If you then run `pnpm next build --experimental-build-mode generate` or `pnpm next build --experimental-build-mode generate-env` which inlines the env variable, it becomes the following code: <img width="2276" height="1340" alt="Screenshot 2025-09-16 at 14 40 14@2x" src="https://github.com/user-attachments/assets/6fc8cbd4-4df8-4d9b-a3e5-fc299e147537" /> Suddenly, it no longer assigns to a variable but to a string, which is invalid JavaScript syntax, throwing the following error: <img width="2314" height="320" alt="Screenshot 2025-09-16 at 14 40 53@2x" src="https://github.com/user-attachments/assets/2c3487be-82e3-4043-aa04-0d98f0a05b4b" /> This PR works around this issue changing up the source code in `getServerSideURL`. I have reported this issue to Next.js: vercel/next.js#83863 --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1211375615406662
1 parent dc732b8 commit ba2ab2f

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

templates/website/src/utilities/getURL.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
import canUseDOM from './canUseDOM'
22

33
export const getServerSideURL = () => {
4-
let url = process.env.NEXT_PUBLIC_SERVER_URL
5-
6-
if (!url && process.env.VERCEL_PROJECT_PRODUCTION_URL) {
7-
return `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL}`
8-
}
9-
10-
if (!url) {
11-
url = 'http://localhost:3000'
12-
}
13-
14-
return url
4+
return (
5+
process.env.NEXT_PUBLIC_SERVER_URL ||
6+
(process.env.VERCEL_PROJECT_PRODUCTION_URL
7+
? `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL}`
8+
: 'http://localhost:3000')
9+
)
1510
}
1611

1712
export const getClientSideURL = () => {

templates/with-vercel-website/src/utilities/getURL.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
import canUseDOM from './canUseDOM'
22

33
export const getServerSideURL = () => {
4-
let url = process.env.NEXT_PUBLIC_SERVER_URL
5-
6-
if (!url && process.env.VERCEL_PROJECT_PRODUCTION_URL) {
7-
return `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL}`
8-
}
9-
10-
if (!url) {
11-
url = 'http://localhost:3000'
12-
}
13-
14-
return url
4+
return (
5+
process.env.NEXT_PUBLIC_SERVER_URL ||
6+
(process.env.VERCEL_PROJECT_PRODUCTION_URL
7+
? `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL}`
8+
: 'http://localhost:3000')
9+
)
1510
}
1611

1712
export const getClientSideURL = () => {

0 commit comments

Comments
 (0)