Skip to content

Commit

Permalink
chore: addresses leftover from #44045 (#44080)
Browse files Browse the repository at this point in the history
## 📖 What's in there?

Yesterday we didn't had time to address leftovers from #44045.
Here it is.

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ]
[e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
tests added
- [ ] Documentation added (from [PR
43814](#43814))
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## 🧪  How to test?

Several tests cases added:
- in dev mode, errors and warning: `NEXT_TEST_MODE=dev pnpm testheadless
--testPathPattern edge-configurable-runtime`
- in build mode, build error for pages on the `edge`:
`NEXT_TEST_MODE=start pnpm testheadless --testPathPattern
edge-configurable-runtime`

Co-authored-by: JJ Kasper <jj@jjsweb.site>
  • Loading branch information
feugy and ijjk committed Jan 3, 2023
1 parent 599ca81 commit c2229a3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
25 changes: 11 additions & 14 deletions packages/next/src/build/analysis/get-page-static-info.ts
Expand Up @@ -313,17 +313,14 @@ export async function getPageStaticInfo(params: {
!isEdgeRuntime(resolvedRuntime)
) {
const options = Object.values(SERVER_RUNTIME).join(', ')
if (typeof resolvedRuntime !== 'string') {
Log.error(
`The \`runtime\` config must be a string. Please leave it empty or choose one of: ${options}`
)
const message =
typeof resolvedRuntime !== 'string'
? `The \`runtime\` config must be a string. Please leave it empty or choose one of: ${options}`
: `Provided runtime "${resolvedRuntime}" is not supported. Please leave it empty or choose one of: ${options}`
if (isDev) {
Log.error(message)
} else {
Log.error(
`Provided runtime "${resolvedRuntime}" is not supported. Please leave it empty or choose one of: ${options}`
)
}
if (!isDev) {
process.exit(1)
throw new Error(message)
}
}

Expand All @@ -346,10 +343,10 @@ export async function getPageStaticInfo(params: {
!isAPIRoute(page.replace(/^\/pages\//, '/'))
) {
const message = `Page ${page} provided runtime 'edge', the edge runtime for rendering is currently experimental. Use runtime 'experimental-edge' instead.`
Log.error(message)

if (!isDev) {
process.exit(1)
if (isDev) {
Log.error(message)
} else {
throw new Error(message)
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/edge-configurable-runtime/index.test.ts
Expand Up @@ -122,7 +122,7 @@ describe('Configurable runtime for pages and API routes', () => {
expect(output.code).toBe(1)
expect(output.stderr).not.toContain(`Build failed`)
expect(output.stderr).toContain(
`error - Page / provided runtime 'edge', the edge runtime for rendering is currently experimental. Use runtime 'experimental-edge' instead.`
`Error: Page / provided runtime 'edge', the edge runtime for rendering is currently experimental. Use runtime 'experimental-edge' instead.`
)
})
})
Expand Down

0 comments on commit c2229a3

Please sign in to comment.