@@ -15,9 +15,6 @@ const SENTRY_WRAPPER_MODULE_NAME = 'sentry-wrapper-module';
1515// Needs to end in .cjs in order for the `commonjs` plugin to pick it up
1616const WRAPPING_TARGET_MODULE_NAME = '__SENTRY_WRAPPING_TARGET_FILE__.cjs' ;
1717
18- // This module is non-public API and may break
19- const nextjsRequestAsyncStorageModulePath = getRequestAsyncLocalStorageModule ( ) ;
20-
2118const apiWrapperTemplatePath = path . resolve ( __dirname , '..' , 'templates' , 'apiWrapperTemplate.js' ) ;
2219const apiWrapperTemplateCode = fs . readFileSync ( apiWrapperTemplatePath , { encoding : 'utf8' } ) ;
2320
@@ -51,32 +48,9 @@ type LoaderOptions = {
5148 wrappingTargetKind : 'page' | 'api-route' | 'middleware' | 'server-component' | 'sentry-init' | 'route-handler' ;
5249 sentryConfigFilePath ?: string ;
5350 vercelCronsConfig ?: VercelCronsConfig ;
51+ nextjsRequestAsyncStorageModulePath ?: string ;
5452} ;
5553
56- function getRequestAsyncLocalStorageModule ( ) : string | undefined {
57- try {
58- // Original location of that module
59- // https://github.com/vercel/next.js/blob/46151dd68b417e7850146d00354f89930d10b43b/packages/next/src/client/components/request-async-storage.ts
60- const location = 'next/dist/client/components/request-async-storage' ;
61- require . resolve ( location ) ;
62- return location ;
63- } catch {
64- // noop
65- }
66-
67- try {
68- // Introduced in Next.js 13.4.20
69- // https://github.com/vercel/next.js/blob/e1bc270830f2fc2df3542d4ef4c61b916c802df3/packages/next/src/client/components/request-async-storage.external.ts
70- const location = 'next/dist/client/components/request-async-storage.external' ;
71- require . resolve ( location ) ;
72- return location ;
73- } catch {
74- // noop
75- }
76-
77- return undefined ;
78- }
79-
8054/**
8155 * Replace the loaded file with a wrapped version the original file. In the wrapped version, the original file is loaded,
8256 * any data-fetching functions (`getInitialProps`, `getStaticProps`, and `getServerSideProps`) or API routes it contains
@@ -98,6 +72,7 @@ export default function wrappingLoader(
9872 wrappingTargetKind,
9973 sentryConfigFilePath,
10074 vercelCronsConfig,
75+ nextjsRequestAsyncStorageModulePath,
10176 } = 'getOptions' in this ? this . getOptions ( ) : this . query ;
10277
10378 this . async ( ) ;
0 commit comments