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

[EdgeRuntime] setImmediate not working after upgrading NextJS 12.3.* #40457

Closed
1 task done
fortezhuo opened this issue Sep 12, 2022 · 3 comments
Closed
1 task done

[EdgeRuntime] setImmediate not working after upgrading NextJS 12.3.* #40457

fortezhuo opened this issue Sep 12, 2022 · 3 comments
Labels
bug Issue was opened via the bug report template. Upstream Related to using Next.js with a third-party dependency. (e.g., React, UI/icon libraries, etc.).

Comments

@fortezhuo
Copy link

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 21.6.0: Wed Aug 10 14:25:27 PDT 2022; root:xnu-8020.141.5~2/RELEASE_X86_64
Binaries:
  Node: 16.15.0
  npm: 8.5.5
  Yarn: 1.22.18
  pnpm: 7.11.0
Relevant packages:
  next: 12.3.1-canary.0
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0

What browser are you using? (if relevant)

How are you deploying your application? (if relevant)

Describe the Bug

After upgrade NextJS from 12.2.5 to 12.3.* (include canary) . An error occurs like below statement

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
warn  - You have enabled experimental feature (runtime) in next.config.js.
warn  - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.

warn  - You are using the experimental Edge Runtime with `experimental.runtime`.
event - compiled client and server successfully in 1406 ms (232 modules)
wait  - compiling / (client and server)...
event - compiled client and server successfully in 860 ms (385 modules)
[Error: A Node.js API is used (setImmediate) which is not supported in the Edge Runtime.
Learn more: https://nextjs.org/docs/api-reference/edge-runtime]
[Error: A Node.js API is used (setImmediate) which is not supported in the Edge Runtime.
Learn more: https://nextjs.org/docs/api-reference/edge-runtime]
wait  - compiling /api/trpc/[trpc] (client and server)...
wait  - compiling /_error (client and server)...
event - compiled client and server successfully in 318 ms (451 modules)
error - (middleware)/node_modules/.pnpm/@trpc+server@10.0.0-proxy-alpha.74/node_modules/@trpc/server/dist/adapters/next.mjs (11:0) @ getPath
error - Cannot read properties of undefined (reading 'trpc')
null
 [TRPCClientError: Unexpected token < in JSON at position 0] {
  meta: undefined,
  shape: undefined,
  data: undefined,
  name: 'TRPCClientError'
}

And FYI, I had enabled EdgeRuntime since 12.2.* and run perfectly with TRPC9 and 10

Expected Behavior

setImmediate should not be thrown as error like prev version. And any workaround for this case will be appreciated.

Link to reproduction

https://github.com/trpc/trpc/tree/main/examples/next-minimal-starter

To Reproduce

  1. Clone or run npx create-next-app --example https://github.com/trpc/trpc --example-path examples/next-minimal-starter trpc-minimal-starter
  2. Enable EdgeRuntime with create next.config.js
module.exports = {
    experimental: {
        runtime: "experimental-edge",
      },
}
  1. Run next dev
@fortezhuo fortezhuo added the bug Issue was opened via the bug report template. label Sep 12, 2022
@balazsorban44 balazsorban44 added the Upstream Related to using Next.js with a third-party dependency. (e.g., React, UI/icon libraries, etc.). label Sep 12, 2022
@balazsorban44
Copy link
Member

The issue you are seeing appears because tRPC is currently not compatible with the Edge runtime, as the error suggests.

The reason it worked before was caused by a bug that messed up the priorities of API Route runtimes #39462, meaning even if you had a global runtime: "experimental-edge" config, your API route was still using Node.js.

To fix your issue, you can set the following in pages/api/trpc/[trpc].ts:

export const config = {
  runtime: "nodejs",
}

which will ensure to explicitly opt into the Node.js runtime for that API route.

@KATT
Copy link
Contributor

KATT commented Sep 12, 2022

cc @fortezhuo feel free to open a feature request in the trpc repo, we def want to support it ☺

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. Upstream Related to using Next.js with a third-party dependency. (e.g., React, UI/icon libraries, etc.).
Projects
None yet
Development

No branches or pull requests

3 participants