Last active
October 20, 2022 11:54
-
-
Save zachgoll/9c606934ffcbbf9077116044fc9d2fc7 to your computer and use it in GitHub Desktop.
Module not found: can't resolve 'fs' error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** THIS FILE THROWS AN ERROR! */ | |
import type { GetServerSideProps } from "next"; | |
import { getFileExistence, formatResult } from './file-utils.ts' | |
type Props = { | |
doesFileExist: boolean; | |
}; | |
export const getServerSideProps: GetServerSideProps = async () => { | |
return { | |
props: { | |
doesFileExist: getFileExistence('/some-file') | |
}, | |
}; | |
}; | |
const ExamplePage = ({ doesFileExist }: Props) => { | |
return <div>File exists?: {formatResult(doesFileExist)}</div>; | |
}; | |
export default ExamplePage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs from 'fs' | |
export function getFileExistence(filepath: string) { | |
return fs.existsSync(filepath) | |
} | |
export function formatResult(fileExistsResult: boolean) { | |
return fileExistsResult ? 'Yes, file exists' : 'No, file does not exist' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment