#my script "register" is crashing bun for some ungodly reason

1 messages · Page 1 of 1 (latest)

primal stump
#
$ bun run src/core/bot/register.ts
[03/10/2025 20:04:01] INFO Application Commands > Refreshing application (/) commands
============================================================
Bun v1.2.23 (cf136713) Windows x64
Windows v.win11_dt
CPU: sse42 avx avx2
Args: "C:\Users\arthu\.bun\bin\bun.exe" "run" "src/core/bot/register.ts"
Features: dotenv jsc transpiler_cache(16) tsconfig tsconfig_paths 
Builtins: "bun:main" "node:buffer" "node:crypto" "node:fs" "node:os" "node:path" "node:util" "node:zlib" "ws" 
Elapsed: 120ms | User: 93ms | Sys: 171ms
RSS: 0.24GB | Peak: 0.24GB | Commit: 0.38GB | Faults: 59650 | Machine: 16.85GB

panic(main thread): Segmentation fault at address 0x18
oh no: Bun has crashed. This indicates a bug in Bun, not your code.

To send a redacted crash report to Bun's team,
please file a GitHub issue using the link below:

 https://bun.report/1.2.23/wr1cf136714BgwgQ2ypi8Bu2h/0Cyh7+0C67vu1CA2AwB

error: script "register" exited with code 3```
#

the script runs this code

#
import { createLogger, createRestManager } from 'discordeno';
import { localize, readDirectory } from 'utils/utils';
import { join } from 'path';
import { TOKEN } from 'utils/variables';

const rest = createRestManager({ token: TOKEN });
const logger = createLogger({ name: 'Application Commands' });

logger.info('Refreshing application (/) commands');

const modules = await readDirectory(join(__dirname, './commands'));

const commands = modules.map((module) => {
  const command = module.default;
  if (!command) throw new Error(`No command exported in ${module.path}`);

  return localize(command);
});

await rest.upsertGlobalApplicationCommands(commands);

logger.info('Successfully reloaded application (/) commands');

process.exit();```
#
export async function readDirectory(dir: string): Promise<any[]> {
  if (!path.isAbsolute(dir)) {
    throw new Error('The provided path must be absolute.');
  }

  const results = fs.readdirSync(path.resolve(dir), { recursive: true, encoding: 'utf-8' });

  const modules = await Promise.all(
    results.map(async (file) => {
      const fullPath = path.resolve(dir, file);

      if (fs.statSync(fullPath).isDirectory()) return null;

      delete require.cache[require.resolve(fullPath)];
      const module = await import(fullPath);
      return module;
    }),
  );

  return modules.filter(Boolean);
}``` i feel like its prob related to this code
#

sometimes i get this error

              ^
TypeError: Requested module is not instantiated yet.
      at requestImportModule (1:11)
      at linkAndEvaluateModule (1:11)
      at requestImportModule (2:1)

Bun v1.2.23 (Windows x64)
error: script "register" exited with code 1```
#
132 | 
133 | const commands = await readDirectory(join(__dirname, './commands'));
134 | bot.commands = new Collection<string, ApplicationCommand>();
135 |
136 | for (const module of commands) {
137 |   const command = module.default;
                        ^
ReferenceError: Cannot access 'default' before initialization.
      at C:\Users\arthu\OneDrive\pocket-tool\src\core\bot\bot.ts:137:19

Bun v1.2.23 (Windows x64)
error: script "register" exited with code 1``` sometimes i get this one, even tho the script is NOT running the bot file