-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix-dynamic-server-usage.js
More file actions
executable file
·47 lines (38 loc) · 1.41 KB
/
fix-dynamic-server-usage.js
File metadata and controls
executable file
·47 lines (38 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
// Get the current file's directory
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Function to add export const dynamic = 'force-dynamic' to server components
function addDynamicExport(filePath) {
if (!fs.existsSync(filePath)) {
console.log(`File not found: ${filePath}`);
return;
}
let content = fs.readFileSync(filePath, 'utf8');
// Check if the file already has the dynamic export
if (content.includes("export const dynamic = 'force-dynamic'")) {
console.log(`File already has dynamic export: ${filePath}`);
return;
}
// Add the dynamic export at the beginning of the file
content = `export const dynamic = 'force-dynamic';\n\n${content}`;
fs.writeFileSync(filePath, content);
console.log(`Added dynamic export to: ${filePath}`);
}
// Paths that had dynamic server usage errors
const pathsToFix = [
'src/app/routes/dashboard/rentals/page.tsx',
'src/app/routes/admin/payments/page.tsx',
'src/app/routes/admin/page.tsx',
'src/app/routes/admin/reports/page.tsx',
'src/app/routes/equipment/new/page.tsx',
'src/app/api/stripe/create-connect-account/route.js'
];
// Fix each file
pathsToFix.forEach(filePath => {
const fullPath = path.join(process.cwd(), filePath);
addDynamicExport(fullPath);
});
console.log('Dynamic server usage fix completed!');