Fix module loading issues with require extension compatibility

- Added robust module loading in server.js with multiple fallback paths
- Created bidirectional symlinks for modules with different naming styles
- Added extension-less symlinks for Node.js CommonJS compatibility
- Updated file copying logic to create all necessary symlinks
- Added symlink creation script that runs on startup
- Improved module error reporting with detailed path information

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-03-07 10:15:47 +00:00
parent 852de32907
commit 16c73bca70
4 changed files with 144 additions and 20 deletions

View File

@@ -19,26 +19,60 @@ const execAsync = util.promisify(exec);
const semver = require('semver'); // For semantic version comparison
// Import custom modules
// Try to import with .js extension first, then fallback to no extension for better compatibility
let RssFeedManager, TransmissionClient, PostProcessor;
// Always use explicit .js extension when importing our own modules
// Helper function to try multiple module paths
function tryRequire(modulePaths) {
let lastError = null;
for (const modulePath of modulePaths) {
try {
return require(modulePath);
} catch (err) {
console.log(`Attempted to load module from ${modulePath}, but got error: ${err.message}`);
lastError = err;
}
}
throw lastError;
}
// Try loading modules with various namings (with and without .js extension, with hyphens or camelCase)
try {
RssFeedManager = require('./modules/rss-feed-manager.js');
const rssPaths = [
'./modules/rss-feed-manager.js',
'./modules/rssFeedManager.js',
'./modules/rss-feed-manager',
'./modules/rssFeedManager'
];
RssFeedManager = tryRequire(rssPaths);
console.log('Successfully loaded RssFeedManager module');
} catch (err) {
console.error('Failed to load RssFeedManager module:', err);
process.exit(1);
}
try {
TransmissionClient = require('./modules/transmission-client.js');
const transmissionPaths = [
'./modules/transmission-client.js',
'./modules/transmissionClient.js',
'./modules/transmission-client',
'./modules/transmissionClient'
];
TransmissionClient = tryRequire(transmissionPaths);
console.log('Successfully loaded TransmissionClient module');
} catch (err) {
console.error('Failed to load TransmissionClient module:', err);
process.exit(1);
}
try {
PostProcessor = require('./modules/post-processor.js');
const processorPaths = [
'./modules/post-processor.js',
'./modules/postProcessor.js',
'./modules/post-processor',
'./modules/postProcessor'
];
PostProcessor = tryRequire(processorPaths);
console.log('Successfully loaded PostProcessor module');
} catch (err) {
console.error('Failed to load PostProcessor module:', err);
process.exit(1);