{ console.log("Reading file.") const lines: string[] = readFile(); const ch" /> { console.log("Reading file.") const lines: string[] = readFile(); const ch" /> { console.log("Reading file.") const lines: string[] = readFile(); const ch"/>

Not able to open file locally

31 Views Asked by At

I have the following code:

import * as fs from "node:fs";

let main = () => {
    console.log("Reading file.")
    const lines: string[] = readFile();

    const charsArray: Array<string[]> = []
    lines.forEach((line: string) => {
        charsArray.push(line.split(""))
    })

    console.log(charsArray);
}

let readFile = (): string[] => {
    console.log("File opened") 
    return fs.readFileSync("input.txt", {encoding:  "utf-8"}).split("\n");
}

console.log("Starting.")
main();

This exact piece of code is working correctly in replit, But when trying to use it locally running bun run index.ts it displays the following in the console:

Starting.
Reading file.
File opened
Segmentation fault at address 0xffffffffffffffff
???:?:?: 0x7ff76a40e1ca in ??? (???)
???:?:?: 0x7ff76be4a15a in ??? (???)
???:?:?: 0x7ff76c0ede66 in ??? (???)

The rout to the file is correct and, as I said, it runs perfectly using replit. I guess I miss configured something, but I cannot find out what.

I copied the package.json that replit gave me & run bun update. Also used bun install just in case.

I'm expecting to see every character in the input.txt file

0

There are 0 best solutions below