@@ -23,11 +23,21 @@ function getNativeBinding() {
2323 throw new Error ( `Unsupported platform: ${ platform } -${ arch } ` ) ;
2424 }
2525
26- // Get the directory of this module - works in both ESM and bundled contexts
27- const currentFileUrl = typeof import . meta !== 'undefined' ? import . meta. url : __filename ;
28- const currentDir = typeof currentFileUrl === 'string' && currentFileUrl . startsWith ( 'file:' )
29- ? path . dirname ( fileURLToPath ( currentFileUrl ) )
30- : __dirname ;
26+ // Determine the current directory - handle ESM, CJS, and bundled contexts
27+ let currentDir : string ;
28+
29+ // Check for ESM context with valid import.meta.url
30+ if ( typeof import . meta !== 'undefined' && import . meta. url ) {
31+ currentDir = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
32+ }
33+ // Fallback to __dirname for CJS/bundled contexts
34+ else if ( typeof __dirname !== 'undefined' ) {
35+ currentDir = __dirname ;
36+ }
37+ // Last resort: use process.cwd() - shouldn't normally hit this
38+ else {
39+ currentDir = process . cwd ( ) ;
40+ }
3141
3242 // The native module is in the 'native' folder at package root
3343 // From dist/index.js, we go up one level to package root, then into native/
@@ -38,8 +48,8 @@ function getNativeBinding() {
3848 : path . resolve ( currentDir , '..' ) ;
3949 const nativePath = path . join ( packageRoot , 'native' , bindingName ) ;
4050
41- // Use createRequire to load .node files in ESM context
42- const require = createRequire ( currentFileUrl ) ;
51+ // Load the native module - use standard require for .node files
52+ // eslint-disable-next-line @typescript-eslint/no-require-imports
4353 return require ( nativePath ) ;
4454}
4555
0 commit comments