@@ -29,7 +29,7 @@ DEALINGS IN THE SOFTWARE.
2929import { isAbsolute , relative } from 'node:path' ;
3030
3131import type { NextConfig } from 'next' ;
32- import { isWasm , transform } from 'next/dist/build/swc/index.js' ;
32+ import * as nextSwcUtils from 'next/dist/build/swc/index.js' ;
3333import { getLoaderSWCOptions } from 'next/dist/build/swc/options.js' ;
3434
3535export interface SWCLoaderOptions {
@@ -136,7 +136,7 @@ async function loaderTransform(this: any, parentTrace: any, source?: string, inp
136136
137137 const swcSpan = parentTrace . traceChild ( 'next-swc-transform' ) ;
138138 return swcSpan . traceAsyncFn ( ( ) =>
139- transform ( source as any , programmaticOptions ) . then ( ( output ) => {
139+ nextSwcUtils . transform ( source as any , programmaticOptions ) . then ( ( output ) => {
140140 if ( output . eliminatedPackages && this . eliminatedPackages ) {
141141 for ( const pkg of JSON . parse ( output . eliminatedPackages ) ) {
142142 this . eliminatedPackages . add ( pkg ) ;
@@ -152,14 +152,25 @@ const EXCLUDED_PATHS = /[\\/](cache[\\/][^\\/]+\.zip[\\/]node_modules|__virtual_
152152export function pitch ( this : any ) {
153153 const callback = this . async ( ) ;
154154 ( async ( ) => {
155+ let isWasm : boolean = false ;
156+
157+ if ( ! ! nextSwcUtils . isWasm ) {
158+ isWasm = await nextSwcUtils . isWasm ( ) ;
159+ // @ts -expect-error Relevant from Next.js >= 16.0.2-canary.12
160+ } else if ( ! ! nextSwcUtils . getBindingsSync ) {
161+ await nextSwcUtils . loadBindings ( ) ;
162+ // @ts -expect-error Relevant from Next.js >= 16.0.2-canary.12
163+ isWasm = nextSwcUtils . getBindingsSync ( ) . isWasm ;
164+ }
165+
155166 if (
156167 // TODO: Evaluate if this is correct after removing pnp compatibility code in SB11
157168 // TODO: investigate swc file reading in PnP mode?
158169 ! process . versions . pnp &&
159170 ! EXCLUDED_PATHS . test ( this . resourcePath ) &&
160171 this . loaders . length - 1 === this . loaderIndex &&
161172 isAbsolute ( this . resourcePath ) &&
162- ! ( await isWasm ( ) )
173+ ! isWasm
163174 ) {
164175 const loaderSpan = mockCurrentTraceSpan . traceChild ( 'next-swc-loader' ) ;
165176 this . addDependency ( this . resourcePath ) ;
0 commit comments