Function calls are not analysed yet
Answered
Lukas posted this in #help-forum
LukasOP
Working on a pretty simple blog, all code is [oss](https://github.com/quick007/blog). I'm trying to render pages, but for some reason it seems to want the files for readFileSync hardcoded in.
Error:
Code:
Error:
⚠ ./lib/getPosts.ts:17:22
lint TP1004 fs.readFileSync(???*0*, "utf-8") is very dynamic
15 |
16 | export const readMDXFile = (path: string) => {
> 17 | const rawContent = fs.readFileSync(path, "utf-8");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18 | return serialize(rawContent, {
19 | parseFrontmatter: true,
20 | mdxOptions: {
- *0* arguments[0]
⚠️ function calls are not analysed yetCode:
export const getAllPosts = async () => {
const files = await globby(["./app/posts/**/page.mdx"]);
console.log(files)
const metadataArray = await Promise.all(
files.map(async (file) => {
const fileData = await readMDXFile(file);
const routeMatch = /\.\/app\/posts\/([^\/]+)\/page\.mdx/;
const date = fileData.frontmatter.posted as string;
return {
...fileData.frontmatter,
posted: new Date(date),
route: `/posts/${file.match(routeMatch)![1]}`,
content: fileData.compiledSource
} as MDXMetaData; // Assuming each file exports a 'metadata' object
})
);
return metadataArray;
};35 Replies
LukasOP
does anyone have any idea
@Lukas does anyone have any idea
its because ./ is a relative path
Answer
LukasOP
dude you're actually a lifesaver
I was about to redo a bunch of stuff to get this to work lmao
nice
glad i could help
@gin its because ./ is a relative path
LukasOP
changed this, it still doesn't seem to work
are u getting the absolute path now?
console.log and check if it really is
should not start with a . (dot)
LukasOP
yep, it is
C:\Users\x\Documents\GitHub\blog\app\posts\it-just-works\page.mdxgood
and the error is still the same one?
LukasOP
yea
@Lukas `C:\Users\x\Documents\GitHub\blog\app\posts\it-just-works\page.mdx`
LukasOP
this is from that console.log
ah good
can u try the thing above
LukasOP
yea 1 sec
isnt readFile async?
oh yeah its with a callback
cant u do it without a callback?
just directly using the return value with await
LukasOP
not as far as I can tell
I was trying to avoid this, but I guess I could just copy and paste directly from the leerob example
anyways I gotta go
thanks for the help