Skip to content

Commit b516d35

Browse files
committed
fix(install): check file existence before loading pre-built binary
- Add existsSync check before trying to load pre-built binary - Prevents false positive when node-pre-gyp finds path but file doesn't exist - Improves error handling and debugging information - Ensures source build is triggered when pre-built binary is missing
1 parent ff67937 commit b516d35

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

scripts/install.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,22 @@ try {
3333
try {
3434
console.log('🔍 Looking for pre-built binary...');
3535
const binding_path = npg.find(package_json_path);
36-
console.log('✅ Found pre-built binary:', binding_path);
36+
console.log('✅ Found pre-built binary path:', binding_path);
3737

38-
// Verify the binary can be loaded (but don't assign to global)
39-
try {
40-
require(binding_path);
41-
console.log('✅ Pre-built binary verified successfully');
42-
} catch (loadError) {
43-
console.log('⚠️ Pre-built binary found but failed to load, rebuilding from source...');
44-
throw loadError; // This will trigger the fallback build
38+
// Check if the binary file actually exists before trying to load it
39+
if (existsSync(binding_path)) {
40+
// Verify the binary can be loaded (but don't assign to global)
41+
try {
42+
require(binding_path);
43+
console.log('✅ Pre-built binary verified successfully');
44+
process.exit(0); // Success, exit early
45+
} catch (loadError) {
46+
console.log('⚠️ Pre-built binary found but failed to load, rebuilding from source...');
47+
throw loadError; // This will trigger the fallback build
48+
}
49+
} else {
50+
console.log('⚠️ Pre-built binary path found but file does not exist, building from source...');
51+
throw new Error(`Pre-built binary not found at ${binding_path}`);
4552
}
4653
} catch (error) {
4754
console.log('⚠️ Pre-built binary not available, building from source...');

0 commit comments

Comments
 (0)