-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.js
More file actions
147 lines (129 loc) Β· 5.14 KB
/
basic.js
File metadata and controls
147 lines (129 loc) Β· 5.14 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Ultra-basic diagnostic script
// Run with: node basic.js
console.log('π ULTRA-BASIC DIAGNOSTICS');
console.log('========================\n');
// Check Node.js
console.log('Node.js Version:', process.version);
console.log('Platform:', process.platform);
console.log('Architecture:', process.arch);
console.log('Current Directory:', process.cwd());
// Check if we can access the file system
try {
const fs = require('fs');
console.log('\nFile System Access: β
');
// Try to read package.json
try {
const packageJson = fs.readFileSync('./package.json', 'utf8');
console.log('package.json exists: β
');
// Try to parse it
try {
const parsed = JSON.parse(packageJson);
console.log('package.json is valid JSON: β
');
console.log('Node.js type:', parsed.type || 'commonjs');
console.log('Main entry point:', parsed.main || 'N/A');
// Check if it has a "type": "module" that might cause issues
if (parsed.type === 'module') {
console.log('\nβ οΈ WARNING: Your package.json has "type": "module" which can cause issues with ts-node.');
console.log('You might need to temporarily remove this line for compatibility with some tools.');
}
} catch (e) {
console.log('package.json is NOT valid JSON: β');
console.log('Error:', e.message);
}
} catch (e) {
console.log('package.json NOT found: β');
console.log('Error:', e.message);
}
// Try to access server directory
try {
fs.accessSync('./src/server', fs.constants.F_OK);
console.log('\nsrc/server directory exists: β
');
// Check if server index file exists
try {
fs.accessSync('./src/server/index.ts', fs.constants.F_OK);
console.log('src/server/index.ts exists: β
');
} catch (e) {
console.log('src/server/index.ts NOT found: β');
}
// Check if server package.json exists
try {
fs.accessSync('./src/server/package.json', fs.constants.F_OK);
console.log('src/server/package.json exists: β
');
} catch (e) {
console.log('src/server/package.json NOT found: β');
}
} catch (e) {
console.log('\nsrc/server directory NOT found: β');
}
// Try to read .env files
console.log('\nEnvironment Files:');
['staging', 'production'].forEach(env => {
try {
fs.accessSync(`./.env.${env}`, fs.constants.F_OK);
console.log(`.env.${env} exists: β
`);
} catch (e) {
console.log(`.env.${env} NOT found: β`);
}
});
} catch (e) {
console.log('\nError accessing file system:', e.message);
}
// Try to use child_process
try {
const { exec } = require('child_process');
console.log('\nChild Process Module: β
');
// Try to run a basic command
exec('node --version', (error, stdout, stderr) => {
if (error) {
console.log('Failed to execute node --version:', error.message);
return;
}
if (stderr) {
console.log('stderr:', stderr);
return;
}
console.log('Verified can run commands: β
(Node.js version:', stdout.trim() + ')');
// Now try npm
exec('npm --version', (error, stdout, stderr) => {
if (error) {
console.log('Failed to execute npm --version:', error.message);
console.log('\nπ΄ DIAGNOSIS: npm appears to be broken or not installed correctly.');
console.log('Try reinstalling Node.js from https://nodejs.org/');
return;
}
console.log('npm available: β
(version:', stdout.trim() + ')');
// Check for TypeScript
exec('npx tsc --version', (error, stdout, stderr) => {
if (error) {
console.log('TypeScript not found or not installed:', error.message);
console.log('\nπ΄ DIAGNOSIS: TypeScript is not installed.');
console.log('Try installing it with: npm install -g typescript');
return;
}
console.log('TypeScript available: β
(version:', stdout.trim() + ')');
// Check for ts-node
exec('npx ts-node --version', (error, stdout, stderr) => {
if (error) {
console.log('ts-node not found or not installed:', error.message);
console.log('\nπ΄ DIAGNOSIS: ts-node is not installed.');
console.log('Try installing it with: npm install -g ts-node');
return;
}
console.log('ts-node available: β
(version:', stdout.trim() + ')');
// Now print summary
console.log('\nβ
SUMMARY: Basic environment checks passed.');
console.log('If you still can\'t run npm commands, try:');
console.log('1. Reinstall Node.js from https://nodejs.org/');
console.log('2. Run: node fix-installation.js');
console.log('3. Try a different terminal or command prompt');
});
});
});
});
} catch (e) {
console.log('\nError using child_process:', e.message);
}
// End message (will appear before async operations finish)
console.log('\nπ°οΈ Running async checks... (results will appear above)');
console.log('If no more output appears, there may be an issue with async operations.');
console.log('In that case, try restarting your computer and trying again.');