Next.js Discord

Discord Forum

Function calls are not analysed yet

Answered
Lukas posted this in #help-forum
Open in Discord
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:
 ⚠ ./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 yet


Code:
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;
};
Answered by gin
its because ./ is a relative path
View full answer

35 Replies

does anyone have any idea
@Lukas does anyone have any idea
its because ./ is a relative path
Answer
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
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)
yep, it is
C:\Users\x\Documents\GitHub\blog\app\posts\it-just-works\page.mdx
good
and the error is still the same one?
yea
what happens when u just use readFile?
fs.readFile()
also console.log the path before u do it
@Lukas `C:\Users\x\Documents\GitHub\blog\app\posts\it-just-works\page.mdx`
this is from that console.log
ah good
can u try the thing above
yea 1 sec
isnt readFile async?
yes
the syntax is very different though
oh yeah its with a callback
cant u do it without a callback?
just directly using the return value with await
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