Next.js Discord

Discord Forum

When batching — Error: Ensure bailed, found path does not match ensure type

Unanswered
Semipalmated Plover posted this in #help-forum
Open in Discord
Semipalmated PloverOP
I have decided to implement batching into several functions, however one of the requests in each batch will fail with a 500 status code and log this:
Error: Ensure bailed, found path does not match ensure type (pages/app)
at ensurePageImpl (.../node_modules/next/dist/server/dev/on-demand-entry-handler.js:483:23) {
  digest: undefined
}


Here's a function that triggers it, even though batching in general is causing issues:
const checkKeywords = async (content) => {
  setGeneratingContent(true);

  const promises = content.map((item) =>
    fetch("/api/check-keywords", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify(item),
    })
      .then((res) => res.json())
      .catch((err) => ({ error: true, message: err.message }))
  );

  try {
    const results = await Promise.all(promises);
    const successfulResults = results.filter((result) => !result.error);

    // Processing retries for failed results
    for (let result of results.filter((r) => r.error)) {
      try {
        const retryResponse = await fetch("/api/check-keywords", {
          method: "POST",
          headers: { "Content-Type": "application/json" },
          body: JSON.stringify(result),
        });
        const retryData = await retryResponse.json();
        successfulResults.push(retryData);
      } catch (retryError) {
        console.error("Retry failed:", retryError);
      }
    }

    const combinedData = successfulResults.flat();

    setGeneratedContent(combinedData);
    setCurrentStep(2);
  } catch (err) {
    console.error("An error occurred while generating content:", err);
  } finally {
    setGeneratingContent(false);
  }
};


Any idea?

5 Replies

Semipalmated PloverOP
bump
Semipalmated PloverOP
Bump
Semipalmated PloverOP
bump
Semipalmated PloverOP
bump
Could you share the code for /api/check-keywords too?