@@ -15,9 +15,6 @@ const SENTRY_WRAPPER_MODULE_NAME = 'sentry-wrapper-module';
15
15
// Needs to end in .cjs in order for the `commonjs` plugin to pick it up
16
16
const WRAPPING_TARGET_MODULE_NAME = '__SENTRY_WRAPPING_TARGET_FILE__.cjs' ;
17
17
18
- // This module is non-public API and may break
19
- const nextjsRequestAsyncStorageModulePath = getRequestAsyncLocalStorageModule ( ) ;
20
-
21
18
const apiWrapperTemplatePath = path . resolve ( __dirname , '..' , 'templates' , 'apiWrapperTemplate.js' ) ;
22
19
const apiWrapperTemplateCode = fs . readFileSync ( apiWrapperTemplatePath , { encoding : 'utf8' } ) ;
23
20
@@ -51,32 +48,9 @@ type LoaderOptions = {
51
48
wrappingTargetKind : 'page' | 'api-route' | 'middleware' | 'server-component' | 'sentry-init' | 'route-handler' ;
52
49
sentryConfigFilePath ?: string ;
53
50
vercelCronsConfig ?: VercelCronsConfig ;
51
+ nextjsRequestAsyncStorageModulePath ?: string ;
54
52
} ;
55
53
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
-
80
54
/**
81
55
* Replace the loaded file with a wrapped version the original file. In the wrapped version, the original file is loaded,
82
56
* any data-fetching functions (`getInitialProps`, `getStaticProps`, and `getServerSideProps`) or API routes it contains
@@ -98,6 +72,7 @@ export default function wrappingLoader(
98
72
wrappingTargetKind,
99
73
sentryConfigFilePath,
100
74
vercelCronsConfig,
75
+ nextjsRequestAsyncStorageModulePath,
101
76
} = 'getOptions' in this ? this . getOptions ( ) : this . query ;
102
77
103
78
this . async ( ) ;
0 commit comments