Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird Server Actions bug when naming a path for a file #67434

Open
GeorgeNabilPro opened this issue Jul 3, 2024 · 1 comment
Open

Weird Server Actions bug when naming a path for a file #67434

GeorgeNabilPro opened this issue Jul 3, 2024 · 1 comment
Labels
bug Issue was opened via the bug report template. Runtime Related to Node.js or Edge Runtime with Next.js. Script (next/script) Related to Next.js Script Optimization.

Comments

@GeorgeNabilPro
Copy link

GeorgeNabilPro commented Jul 3, 2024

Link to the code that reproduces this issue

https://codesandbox.io/p/sandbox/nextjs-error-code-fccprj

To Reproduce

In my project, when some server action is called it calls the function saveFile, which looks like this:

async function saveFile(
  file: File,
  documentHash: string
) {
  const data = await file.arrayBuffer();
  await fs.appendFile(`./public/${documentHash}.pdf`, Buffer.from(data));
  return;
}

this goes well without any errors, however, when just changing the code to:

async function saveFile(
  file: File,
  documentHash: string
) {
  const data = await file.arrayBuffer();
  const path = `./public/assets/materials/${documentHash}.${file.name.split(".").pop()}`;
  await fs.appendFile(path, Buffer.from(data));
  return;
}

I tried many ways to add the file extension to the file path, but all of them caused the same error:

Error: Only plain objects, and a few built-ins, can be passed to Client Components from Server Components. Classes or null prototypes are not supported.
    at stringify (<anonymous>)

Current vs. Expected behavior

It is expected to have the file name with the proper extension, but this not happening

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro
  Available memory (MB): 16126
  Available CPU cores: 20
Binaries:
  Node: 21.5.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.2.4 // Latest available version is detected (14.2.4).
  eslint-config-next: 14.2.4
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.5.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Runtime, Script (next/script)

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

No response

@GeorgeNabilPro GeorgeNabilPro added the bug Issue was opened via the bug report template. label Jul 3, 2024
@github-actions github-actions bot added Runtime Related to Node.js or Edge Runtime with Next.js. Script (next/script) Related to Next.js Script Optimization. labels Jul 3, 2024
@GeorgeNabilPro GeorgeNabilPro changed the title Weir Server Actions bug when naming a path for a file Weird Server Actions bug when naming a path for a file Jul 3, 2024
@GeorgeNabilPro
Copy link
Author

Edit

I found that the problem is with the path being

./public/assets/materials/...

Because this directory did not exist on the system, when I tried to use a path like this:

./public/....

There were no errors. But still, I don't know what caused this weird behavior and why the error was not clear enough

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Runtime Related to Node.js or Edge Runtime with Next.js. Script (next/script) Related to Next.js Script Optimization.
Projects
None yet
Development

No branches or pull requests

1 participant