Don't use `fs` in the `pages` directory, since next.js suppose that files in `pages` directory are running in browser environment.
You could put the util file which uses `fs` to other directory such as `/core`
Then `require` the util in `getStaticProps` which runs in node.js environment.
```tsx
// /pages/myPage/index.tsx
import View from './view';
export default View;
export async function getStaticProps() {
const util = require('core/some-util-uses-fs').default; // getStaticProps runs in nodes
const data = await util.getDataFromDisk();
return {
props: {
data,
},
};
}
```
Don't use `fs` in the `pages` directory, since next.js suppose that files in `pages` directory are running in browser environment.
You could put the util file which uses `fs` to other directory such as `/core`
Then `require` the util in `getStaticProps` which runs in node.js environment.
```tsx
// /pages/myPage/index.tsx
import View from './view';
export default View;
export async function getStaticProps() {
const util = require('core/some-util-uses-fs').default; // getStaticProps runs in nodes
const data = await util.getDataFromDisk();
return {
props: {
data,
},
};
}
```