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

Error: The script will never generate a response. #57

Open
vacom opened this issue Oct 3, 2024 · 12 comments
Open

Error: The script will never generate a response. #57

vacom opened this issue Oct 3, 2024 · 12 comments
Assignees
Labels
bug Something isn't working

Comments

@vacom
Copy link

vacom commented Oct 3, 2024

After the following issues (#45 and #42) were resolved I was finally able to build my App.

In the meantime I decided to run the following command to test and run App to see if it was working properly, but I'm having the following problem:

wrangler dev --port 3003

When I open in the browser, I immediately get the following error

Error: The script will never generate a response.
    at async Object.fetch (file:///Users/myuser/Documents/projects/demo/node_modules/miniflare/dist/src/workers/core/entry.worker.js:1029:22)

Strangely enough, the console shows the following errors

[wrangler:inf] GET / 500 Internal Server Error (125ms)
[wrangler:inf] GET /favicon.ico 500 Internal Server Error (6ms)
✘ [ERROR] Uncaught (in promise) Error: NextRouter was not mounted. https://nextjs.org/docs/messages/next-router-not-mounted

By the way, I had to add the following environment variables so that it could at least run without errors (before opening in the browser) otherwise it says the following:

Environment variables based on the docs https://opennext.js.org/cloudflare/troubleshooting#my-app-fails-to-build-when-i-import-a-specific-npm-package

WRANGLER_BUILD_CONDITIONS=""
WRANGLER_BUILD_PLATFORM="node"

Without the variables above it outputs the following error

✘ [ERROR] Could not resolve "jose"

   .worker-next/.next/standalone/node_modules/openid-client/lib/helpers/keystore.js:1:21:
     1 │ const jose = require('jose');
       ╵                      ~~~~~~

 The module "./dist/browser/index.js" was not found on the file system:

   .worker-next/.next/standalone/node_modules/jose/package.json:66:17:
     66 │       "browser": "./dist/browser/index.js",
        ╵                  ~~~~~~~~~~~~~~~~~~~~~~~~~

 You can mark the path "jose" as external to exclude it from the bundle, which will remove this error. You can also surround this "require" call with a try/catch block to handle this failure at run-time instead of bundle-time.

PS: I don't use this package jose in my project

Now the problem is to help describe how to cause/replicate this error because I generated a new project from scratch with Yarn and both the build and start run without the app breaking, so most likely it may be a unique case of my project since it already has its size, so I leave this issue open if anyone knows if I'm doing something wrong or if someone else is experiencing the same thing.

@sorenhansendk
Copy link

sorenhansendk commented Oct 3, 2024

I can deploy my app now (after upgrading to @opennextjs/[email protected])

But I'm not able to run it locally or in the worker in Cloudflare. My browser shows this:

Error: The script will never generate a response.
    at async Object.fetch (file:///{removed}/node_modules/miniflare/dist/src/workers/core/entry.worker.js:1029:22)

And the output from Wrangler shows this:

✘ [ERROR] Uncaught (async) Error: Invariant: renderHTML should not be called in minimal mode

      at Xe.renderHTMLImpl
  (file:///{removed}/packages/application/.wrangler/tmp/dev-3Gm2Gb/index.js:404:9251)
      at
  file:///{removed}/packages/application/.wrangler/tmp/dev-3Gm2Gb/index.js:404:9176
      at m.trace
  (file:///{removed}/packages/application/.wrangler/tmp/dev-3Gm2Gb/index.js:333:249036)
      at Xe.renderHTML
  (file:///{removed}/packages/application/.wrangler/tmp/dev-3Gm2Gb/index.js:404:9123)
      at Fa
  (file:///{removed}/packages/application/.wrangler/tmp/dev-3Gm2Gb/index.js:372:23698)
      at Yn.responseCache.get.routeKind
  (file:///{removed}/packages/application/.wrangler/tmp/dev-3Gm2Gb/index.js:374:1436)
      at o.get
  (file:///{removed}/packages/application/.wrangler/tmp/dev-3Gm2Gb/index.js:387:77655)
      at Xe.renderToResponseWithComponentsImpl
  (file:///{removed}/packages/application/.wrangler/tmp/dev-3Gm2Gb/index.js:374:389)
      at
  file:///{removed}/packages/application/.wrangler/tmp/dev-3Gm2Gb/index.js:372:15795
      at m.trace
  (file:///{removed}/packages/application/.wrangler/tmp/dev-3Gm2Gb/index.js:333:249036)

✘ [ERROR] Uncaught (in response) Error: The script will never generate a response.

✘ [ERROR] Uncaught (async) Error: Promise will never complete.

Adding the environment variables (WRANGLER_BUILD) don't fix the issue for me.

@vicb
Copy link
Contributor

vicb commented Oct 4, 2024

Thanks for reporting!
It would be helpful if you can add a minimal repro of the error.

@vicb vicb added bug Something isn't working needs repro labels Oct 4, 2024
@vacom
Copy link
Author

vacom commented Oct 4, 2024

Here are the steps to reproduce:

First error scenario [ERROR] Could not resolve "jose"

  1. Create a new NextJS project with T3 Stack npm create t3-app@latest (choose: Pages Dir (not the App Dir), TypeScript, Tailwind CSS, tRPC, NextAuth, Prisma, PostgreSQL);
  2. Don't worry about database errors, they may occur but they won't break the functioning of the demo since the Welcome Page endpoint demo is static and serves as a good example to reproduce the problems.
  3. Add some random strings to DISCORD_CLIENT_ID and DISCORD_CLIENT_SECRET on the .envfile just to be able to run the app with npm run dev;
  4. The Welcome Page should renders with npm run dev and tTPC endpoint should load with Hello from tRPC
  5. Follow the Get Started from https://opennext.js.org/cloudflare/get-started#existing-nextjs-apps
  6. Run npm run build:worker
  7. Run npm run dev:worker change the port to use 3000
  8. You will see the Jose Error:

Second error scenario Error: The script will never generate a response

  1. Fallow the same steps and the 1 error but add WRANGLER_BUILD_CONDITIONS="" WRANGLER_BUILD_PLATFORM="node" to the .env file (https://opennext.js.org/cloudflare/troubleshooting#my-app-fails-to-build-when-i-import-a-specific-npm-package)
  2. Run npm run build:worker
  3. Run npm run dev:worker change the port to use 3000
  4. Open in the browser and you will see the Loading tRPC query... stuck open devtools -> network -> open the endpoint its a 500, open the response tab and you will see the Error: The script will never generate a response. check for more details on the console/terminal running the app;
  5. Another way to see this error is by clicking on the "Sign In" Button on the Welcome Page;

T3 Stack has a similar packages to my project, so was the best way I could think of to reproduce the problems, @vicb I hope it helps

@vicb
Copy link
Contributor

vicb commented Oct 4, 2024

It does help, thanks!

I presume that's an issue with NextAuth but I'll take a closer look next week.

@vacom
Copy link
Author

vacom commented Oct 9, 2024

@vicb any luck on this issue?

@vicb
Copy link
Contributor

vicb commented Oct 10, 2024

I hope that will be solved when integrate with existing code in opennext-aws - see details

@vacom
Copy link
Author

vacom commented Oct 11, 2024

I've been following the updates and updating the T3 Stack example repo and the errors are improving, now it says the following

Error: Dynamic require of "/.next/server/pages/api/auth/[...nextauth].js" is not supported

Error: Dynamic require of "/.next/server/pages/api/trpc/[trpc].js" is not supported

[DeprecationWarning] [unenv] [node:url] DEP0169: `url.parse()` behavior is not standardized and prone to errors that have security implications. Use the WHATWG URL API instead. CVEs are not issued for `url.parse()` vulnerabilities.

So no more the Error: The script will never generate a response.

@Qocotzxin
Copy link

I'm getting a similar error when using the instrumentation hook to load Sentry configuration for the server:

✘ [ERROR] Uncaught (in response) Error: The script will never generate a response.


✘ [ERROR] Uncaught (async) Error: Promise will never complete.


✘ [ERROR] Uncaught (in promise) Error: An error occurred while loading instrumentation hook: Dynamic require of "/.next/server/instrumentation" is not supported

I know instrumentation hook is still experimental, but I haven't seen anything in the docs mentioning a specific issue to this. Is this feature supported by this lib? Is it related to this package or to wrangler SDK? Thanks in advance!

@Benjamin-Dobell
Copy link

Benjamin-Dobell commented Dec 26, 2024

At least in my case, renderHTML should not be called in minimal mode occurs when there's an issue loading your route. Basically if an attempt to require your route fails, that error is swallowed and it attempts to render the fallback route.

In my case I've been trying to get something, anything deployed to Cloudflare for days, so I'm deploying just a single API route. So when my API route file fails to require/execute the Next.js route component is an empty object and it attempts to render the fallback route. This fails with:

renderHTML should not be called in minimal mode

The actual underlying issue in my case is, well, much more complex. There's not one, I've fixed (worked around) dozens of issues with the workerd runtime thus far.

Currently I'm locking horns with @prisma/adapter-pg-worker, which is weirdly enough failing to require("node:events") in the module format it expects 🤷 Anyway, that's unlikely to be your issue, but the real problem here is OpenNext is swallowing route errors.

@vicb
Copy link
Contributor

vicb commented Jan 30, 2025

Is this still an issue with the latest version?
If it is, please link a GH repository with a repro - it is quite time consuming to read, understand, and replicate with only instructions so we tend to prioritize issues with a minimal repro.

Thanks!

@SamyPesse
Copy link

@vicb It's still happening with the latest version.

You can reproduce it with the following example (we are starting a new Next.js app so it's almost an empty one):

  1. Clone the commit GitbookIO/gitbook@b145bbe
  2. Run bun install in the root directory (you need bun > 1.2.0)
  3. Move to packages/gitbook-v2
  4. Run bun run build:v2:cloudflare (it'll just build with the latest version of opennext)
  5. Run bun run dev:v2:cloudflare to see it crashes locally (by opening http://localhost:8771/static/url/docs.gitbook.com)
  6. Or deploy it to a worker by renaming the worker in wrangler.toml and running bun run deploy:v2:cloudflare (by opening /static/url/docs.gitbook.com on the deployed URL)

In both cases, it failed: locally and deployed, while it works with next or on Vercel:

Image Image

@vicb
Copy link
Contributor

vicb commented Jan 31, 2025

@vicb It's still happening with the latest version.

You should use the latest version of wrangler too :)
The apps need a few polyfills to run on the cloudflare runtime and those are released with wrangler.

Image

Not enough to solve the issue first issue but it fixes module.findSourceMap.

A few more notes:

use cache; is not supported

You can not use process.env at top level:

export const GITBOOK_API_URL = process.env.GITBOOK_API_URL ?? 'https://api.gitbook.com';

// And call that in a request context
export const getApiUrl = () => process.env.GITBOOK_API_URL ?? 'https://api.gitbook.com';

Documentation for that is coming...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

6 participants