SvelteKit on Pages build not succeeding

I am trying to deploy a SvelteKit application with pages. The application uses static files to store and read content. I am having an issue with loading readFileSync based on the below error:

The package "path" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

This is related to the below code.

import { readFileSync } from "fs";

export function getFileContents(path: string) {
  try {
    let content = readFileSync(path, "utf8");
    if (content !== undefined) {
      return content;
    }
  } catch (e: any) {
    console.log(e.message);
    return Error(e.message);
  }
}

How can I fix this or is it not possible? My understanding is that this should be possible.

Workers doesn’t have a file system and it doesn’t have the fs module. It isn’t NodeJS so you will need to use browser APIs.

1 Like

Vexxing, but thanks!