Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[⚡ Feature]: Allow split deployments with latent nodejs runtime functions #845

Open
1 task done
nickbabcock opened this issue Aug 1, 2024 · 1 comment · May be fixed by #867
Open
1 task done

[⚡ Feature]: Allow split deployments with latent nodejs runtime functions #845

nickbabcock opened this issue Aug 1, 2024 · 1 comment · May be fixed by #867
Labels
enhancement New feature or request

Comments

@nickbabcock
Copy link
Contributor

Description

I'm currently running a next.js app on vercel. The next.js app contains a mix of edge and nodejs APIs, however the nodejs endpoints do not run on vercel (due to a body size limit), and are deployed on a separate server. Vercel will proxy to this server with the help of a conditional rewrite defined in the next.config.js

{
  rewrites: async () => ({
    beforeFiles: process.env.PROXY_NODE_URL
      ? [
          "/api/my-node-js-endpoint",
          // ...
        ].map((source) => ({
          source,
          destination: `${process.env.PROXY_NODE_URL}${source}`,
        }))
      : undefined,
    })
}

This allows the best of both worlds: the entire API can be defined in next.js and ran locally, and then divvied up for a production deployment.

I want to try out cloudflare's Next on pages but am receiving the following error:

⚡️ ERROR: Failed to produce a Cloudflare Pages build from the project.
⚡️
⚡️ The following routes were not configured to run with the Edge Runtime:
⚡️ - /api/my-node-js-endpoint

As far as I can tell, the invalid function check is a heuristic that is eagerly throwing an error for functions that can never be invoked.

My request:

  • Allow the build system to ignore invalid functions based on a CLI argument (--force 🤔 ?)
  • Or add heuristics that won't consider a function invalid if a rewrite will always take precedence

Additional Information

No response

Would you like to help?

  • Would you like to help implement this feature?
@nickbabcock nickbabcock added the enhancement New feature or request label Aug 1, 2024
@nickbabcock
Copy link
Contributor Author

I tested a build that removed the check:

diff --git a/packages/next-on-pages/src/buildApplication/processVercelFunctions/invalidFunctions.ts b/packages/next-on-pages/src/buildApplication/processVercelFunctions/invalidFunctions.ts
index d6d92d7..b3a0ff9 100644
--- a/packages/next-on-pages/src/buildApplication/processVercelFunctions/invalidFunctions.ts
+++ b/packages/next-on-pages/src/buildApplication/processVercelFunctions/invalidFunctions.ts
@@ -45,13 +45,6 @@ export async function checkInvalidFunctions(
 
 	await tryToFixInvalidFuncsWithValidIndexAlternative(collectedFunctions);
 	await tryToFixInvalidDynamicISRFuncs(collectedFunctions);
-
-	if (collectedFunctions.invalidFunctions.size > 0) {
-		await printInvalidFunctionsErrorMessage(
-			collectedFunctions.invalidFunctions,
-		);
-		process.exit(1);
-	}
 }
 
 /**

And I was able to successfully able to port the application to cloudflage pages, and everything works as expected.

This confirms that the check is not exhaustive and can reject good deployments.

Not sure how this should be incorporated (I think I'm still leaning towards --force), but I'd love to not need to maintain a patched version of next-on-pages.

nickbabcock added a commit to nickbabcock/next-on-pages that referenced this issue Aug 27, 2024
The presence of invalid functions shouldn't force a build failure as a
deployment can still be valid (and even correct as outlined in cloudflare#845)
with invalid functions.

This commit adds a `--force` cli option (bike-shedding welcomed) that
allows users to opt to ignore invalid functions (and skip more checks in
the future?).

Closes cloudflare#845
nickbabcock added a commit to nickbabcock/next-on-pages that referenced this issue Aug 27, 2024
The presence of invalid functions shouldn't force a build failure as a
deployment can still be valid (and even correct as outlined in cloudflare#845)
with invalid functions.

This commit adds a `--force` cli option (bike-shedding welcomed) that
allows users to opt to ignore invalid functions (and skip more checks in
the future?).

Closes cloudflare#845
nickbabcock added a commit to nickbabcock/next-on-pages that referenced this issue Aug 27, 2024
The presence of invalid functions shouldn't force a build failure as a
deployment can still be valid (and even correct as outlined in cloudflare#845)
with invalid functions.

This commit adds a `--force` cli option (bike-shedding welcomed) that
allows users to opt to ignore invalid functions (and skip more checks in
the future?).

Closes cloudflare#845
@nickbabcock nickbabcock linked a pull request Aug 27, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant