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

Instrumentation loads as client component, even in Node runtime #57563

Closed
1 task done
bbangert opened this issue Oct 27, 2023 · 7 comments · Fixed by #60984
Closed
1 task done

Instrumentation loads as client component, even in Node runtime #57563

bbangert opened this issue Oct 27, 2023 · 7 comments · Fixed by #60984
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. locked

Comments

@bbangert
Copy link

bbangert commented Oct 27, 2023

Link to the code that reproduces this issue

https://github.com/bbangert/nextjs-instrumentation-bug

To Reproduce

  1. Create Next.js app
  2. Add instrumentation.ts file.
  3. Include code to toggle loading of instrumentation-node file per Documentation
  4. Put "import 'server-only';" in instrumentation-node file.
  5. Build app

Current vs. Expected behavior

Current behavior is that Nextjs errors as instrumentation.ts is a client component, and cannot load server-only code.

Error:

ReactServerComponentsError:

You're importing a component that needs server-only. That only works in a Server Component but one of its parents is marked with "use client", so it's a Client Component.
Learn more: https://nextjs.org/docs/getting-started/react-essentials

   ╭─[/home/user/Programming/instrumentation-bug/instrumentation-node.ts:1:1]
 1 │ import 'server-only';
   · ─────────────────────
 2 │ 
 3 │ export const Nothing = 0;
   ╰────

One of these is marked as a client entry with "use client":
  ./instrumentation-node.ts
  ./instrumentation.ts

Expected behavior is that code targeted to run in Node runtime only should be capable of being marked as server-only code.

Verify canary release

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

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #96-Ubuntu SMP Wed Sep 20 08:23:49 UTC 2023
Binaries:
  Node: 18.18.2
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: N/A
Relevant Packages:
  next: 14.0.0
  eslint-config-next: 14.0.0
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Not sure

Additional context

No response

NEXT-2181

@bbangert bbangert added the bug Issue was opened via the bug report template. label Oct 27, 2023
@ariesclark
Copy link

Still an issue in 14.0.2.

@paschaldev
Copy link

Can confirm this issue exists in v13.5 also

@Artiesy

This comment has been minimized.

@olivierr91
Copy link

I have this issue as well

@AntonAndreevichMoroz
Copy link

I'm experiencing the same problem on Next.js version 14.0.5-canary.44.
The main problem is that even in NEXT_RUNTIME === "nodejs" I can't import functions that are marked 'use server' or import 'server-only'

@khuezy
Copy link
Contributor

khuezy commented Jan 19, 2024

Should instrumentation also apply the experimental.serverComponentsExternalPackages too? It looks like it ignores that causing some external package issues.

@huozhi huozhi added the linear: next Confirmed issue that is tracked by the Next.js team. label Jan 22, 2024
huozhi added a commit that referenced this issue Jan 24, 2024
### What

When users're using nextjs server API that break the build, and error
with incorrect client components usage.
Instrument should be treated as server components or server-only build
target, instead of being treated as client components.

### How

We added a new layer `instrument` for instrument hook bundling, and
apply it with the rsc server webpack loaders

Fixes #57563
Closes NEXT-2181
Closes NEXT-1994
Copy link
Contributor

github-actions bot commented Feb 8, 2024

This closed issue has been automatically locked because it had no new activity for 2 weeks. 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 added the locked label Feb 8, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 8, 2024
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. linear: next Confirmed issue that is tracked by the Next.js team. locked
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants