File System
getStaticProps 不知道為什麼,getStaticProps 裡面的 fs 時有時無。這裡 似乎有關於這個問題的回答,但無效 正常一 這個版本,就可以正常運作,證明 getStaticProps 裡可以用 fs // pages/index.js import fs from 'fs/promises' export async function getStaticProps() { console.log(await fs.stat('./content/index.md')); const posts = ['index.md'] console.log({ posts }) return { props: { posts }, }; } 正常二 在這個版本,將 fs 相關程式碼移到 util/fsTest.js,也就是測試如果是引用另一個模組中 fs 相關的函數。經過證明,也是可以的 // util/fsTest.js import fs from 'fs/promises' export default async function dirs(){ return await fs.readdir(`${process.cwd()}/content`) } // pages/index.js import fsTest from '../util/fsTest' export async function getStaticProps() { const posts = ['index....