Cannot import `dd-trace` within `getServerSideProps` after Next Patch Update
See original GitHub issueVerify canary release
- I verified that the issue exists in Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: x64
Version: Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:22 PDT 2022; root:xnu-8020.121.3~4/RELEASE_X86_64
Binaries:
Node: 16.14.0
npm: 8.3.1
Yarn: 1.22.19
pnpm: 7.1.7
Relevant packages:
next: 12.1.7-canary.26
react: 17.0.2
react-dom: 17.0.2
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
When having this code in some page:
import Tracer from 'dd-trace';
export const getServerSideProps = async () => {
return Tracer.trace('foo', { resource: 'bar' }, async () => {
return { props: {} };
});
}
The next build
fails since next@12.1.16
but succeeded with next@12.1.15
. The error stack is:
Failed to compile.
./node_modules/.pnpm/@datadog+native-appsec@1.2.0/node_modules/@datadog/native-appsec/vendor/darwin-x64-unknown/appsec.node
Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)
Import trace for requested module:
./node_modules/.pnpm/@datadog+native-appsec@1.2.0/node_modules/@datadog/native-appsec/vendor/ sync ^\.\/.*\/appsec\.node$
./node_modules/.pnpm/@datadog+native-appsec@1.2.0/node_modules/@datadog/native-appsec/lib/loader.js
./node_modules/.pnpm/@datadog+native-appsec@1.2.0/node_modules/@datadog/native-appsec/index.js
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/packages/dd-trace/src/appsec/callbacks/ddwaf.js
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/packages/dd-trace/src/appsec/callbacks/index.js
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/packages/dd-trace/src/appsec/rule_manager.js
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/packages/dd-trace/src/appsec/index.js
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/packages/dd-trace/src/proxy.js
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/packages/dd-trace/index.js
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/index.js
./pages/search/index.tsx
./node_modules/.pnpm/@datadog+pprof@0.4.0/node_modules/@datadog/pprof/out/src/index.js
Module not found: Can't resolve 'fs' in '/Users/viktor/projects/freiheit/ngshop/discover/apps/discover-ui/node_modules/.pnpm/@datadog+pprof@0.4.0/node_modules/@datadog/pprof/out/src'
Import trace for requested module:
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/packages/dd-trace/src/profiling/profiler.js
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/packages/dd-trace/src/profiling/index.js
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/packages/dd-trace/src/profiler.js
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/packages/dd-trace/src/proxy.js
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/packages/dd-trace/index.js
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/index.js
./pages/search/index.tsx
./node_modules/.pnpm/@datadog+pprof@0.4.0/node_modules/@datadog/pprof/out/src/sourcemapper/sourcemapper.js
Module not found: Can't resolve 'fs' in '/Users/viktor/projects/freiheit/ngshop/discover/apps/discover-ui/node_modules/.pnpm/@datadog+pprof@0.4.0/node_modules/@datadog/pprof/out/src/sourcemapper'
Import trace for requested module:
./node_modules/.pnpm/@datadog+pprof@0.4.0/node_modules/@datadog/pprof/out/src/index.js
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/packages/dd-trace/src/profiling/profiler.js
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/packages/dd-trace/src/profiling/index.js
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/packages/dd-trace/src/profiler.js
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/packages/dd-trace/src/proxy.js
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/packages/dd-trace/index.js
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/index.js
./pages/search/index.tsx
./node_modules/.pnpm/@datadog+pprof@0.4.0/node_modules/@datadog/pprof/out/third_party/cloud-debug-nodejs/src/agent/io/scanner.js
Module not found: Can't resolve 'fs' in '/Users/viktor/projects/freiheit/ngshop/discover/apps/discover-ui/node_modules/.pnpm/@datadog+pprof@0.4.0/node_modules/@datadog/pprof/out/third_party/cloud-debug-nodejs/src/agent/io'
Import trace for requested module:
./node_modules/.pnpm/@datadog+pprof@0.4.0/node_modules/@datadog/pprof/out/src/sourcemapper/sourcemapper.js
./node_modules/.pnpm/@datadog+pprof@0.4.0/node_modules/@datadog/pprof/out/src/index.js
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/packages/dd-trace/src/profiling/profiler.js
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/packages/dd-trace/src/profiling/index.js
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/packages/dd-trace/src/profiler.js
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/packages/dd-trace/src/proxy.js
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/packages/dd-trace/index.js
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/index.js
./pages/search/index.tsx
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/packages/datadog-core/src/storage/async_hooks.js
Module not found: Can't resolve 'async_hooks' in '/Users/viktor/projects/freiheit/ngshop/discover/apps/discover-ui/node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/packages/datadog-core/src/storage'
Did you mean './async_hooks'?
Requests that should resolve in the current directory need to start with './'.
Requests that start with a name are treated as module requests and resolve within module directories (node_modules, /Users/viktor/.nvm/versions/node/v16.14.0/bin/node, /Users/viktor/Library/pnpm/global/5/.pnpm/node_modules, /Users/viktor/projects/freiheit/ngshop/discover/apps/discover-ui/node_modules/.pnpm/node_modules, /Users/viktor/projects/freiheit/ngshop/discover/apps/discover-ui).
If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.
Import trace for requested module:
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/packages/datadog-core/src/storage/index.js
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/packages/datadog-core/index.js
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/packages/dd-trace/src/tracer.js
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/packages/dd-trace/src/proxy.js
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/packages/dd-trace/index.js
./node_modules/.pnpm/dd-trace@2.8.0/node_modules/dd-trace/index.js
./pages/search/index.tsx
Expected Behavior
I would have expected a “patch” update to not cause breaking issues. It seems like the “dd-trace” package cannot use the Node-native packages anymore even though it is only contained within getServerSideProps
and hence runs only on server-side.
To Reproduce
- Get any Next app from Scratch.
- Install the
dd-trace
package (currently using: “dd-trace”: “2.8.0”) - Add above code snippet to any page
- Run
next build
command
Issue Analytics
- State:
- Created a year ago
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Data Fetching: getServerSideProps - Next.js
Fetch data on each request with `getServerSideProps`. ... Instead, directly import the logic used inside your API Route into getServerSideProps .
Read more >Release Notes — ddtrace documentation
httpx: Fixes an incompatibility from httpx==0.23.1 when the URL.raw property is ... Fix error in the agent response payload when the user disabled...
Read more >next.js - getServerSideProps not working returning undefined ...
This looks like it's a non-page component. You can't use getServerSideProps in non-page components. Try calling the API from your page file ...
Read more >Refreshing Server-Side Props - Next.js - Josh W Comeau
This is fine in some cases, but we can't assume a fast network; even if your getServerSideProps call is Blazing Fast™, a user...
Read more >ddtrace-run command not found
Installation + Quickstart — ddtrace documentation - Read the Docs ddtrace.readthedocs.io ... Cannot import `dd-trace` within `getServerSideProps` after Next ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No worries, thanks for taking a look 🙌
ok. Thanks, I will investigate on this.
I actually have it like so:
This seemed to have worked in the earlier version, but stopped working now. But knowing this, I could rewrite the code of course to overcome this problem 👍