Multi-platform dependency cannot be correctly used with Next.js #64827
Labels
bug
Issue was opened via the bug report template.
Instrumentation
Related to Next.js Instrumentation.
Output (export/standalone)
Related to the the output option in `next.config.js`.
Runtime
Related to Node.js or Edge Runtime with Next.js.
Link to the code that reproduces this issue
https://github.com/bripkens/nextjs-reproducer-oteljs
To Reproduce
Current vs. Expected behavior
I would expect that Next.js honors the
package.json
hints to use different filesfor web browsers. Specifically these hints:
https://github.com/open-telemetry/opentelemetry-js/blob/31eb60dc99dc066cf2085864f2727eb29ee76e91/experimental/packages/opentelemetry-instrumentation/package.json#L19-L24
However, when starting the dev server it can be observed that it is trying to transpile
the Node.js module variant instead of the browser variant. This is then resulting in
Webpack warnings that are also confirming this problem:
Note the above output lines
Creating Webpack config:…
. I have tried to analyze/improveon the Webpack config within the reproducer. However, I have observed that the Webpack config with the Node.js target is always used to transpile the module chain in question.
https://github.com/bripkens/nextjs-reproducer-oteljs/blob/main/src/app/layout.tsx#L9-L11
Note that it is possible to hide this error by also setting Webpack's
aliasFields
config to['browser']
for the Node.js target. However, this is bound to cause issues with Next.js' server-side OpenTelemetry support.Summarizing, I expect that Next.js will leverage the Node.js platform modules for server-side code and the browser platform modules for client-side code.
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:25 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6030 Available memory (MB): 36864 Available CPU cores: 12 Binaries: Node: 18.17.0 npm: 9.6.7 Yarn: N/A pnpm: 8.12.1 Relevant Packages: next: 14.2.2 // Latest available version is detected (14.2.2). eslint-config-next: N/A react: 18.2.0 react-dom: 18.2.0 typescript: 5.4.5 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Instrumentation, Output (export/standalone), Runtime
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local), next start (local), Vercel (Deployed), Other (Deployed)
Additional context
No response
The text was updated successfully, but these errors were encountered: