Back

NextJS and Appwrite (TypeError: e._formData.get)

  • 0
  • Web
  • Cloud
Olly
8 Apr, 2024, 15:59

This error occurs when attempting to use server actions in NextJS with appwrite.

First of all, all credit goes to @antho1404 (on Github). He identified that the issue is related to an import of the isomoprhic-form-data library overriding the FormData with an invalid object and further determined that it only happens when the library is imported rather than loaded over a cdn for example. The solution he came up with is to override the library with a dummy file.

One solution to fix this is to "override" this library with Webpack.

import weback from 'webpack' const nextConfig = { webpack(config) { config.plugins.push( new webpack.NormalModuleReplacementPlugin( /^isomorphic-form-data$/, ${config.context}/form-data-mock.js ) ); return config; }, };

Then, create a form-data-mock.js in the root and the error goes away.

My question is: instead of this hacky approach, is there a way to fix this import in future versions, so that the community can take full advantage of server actions? With this error, server actions in NextJS are completely unuseable. All credit and enormous gratitude again to @antho1404 for diving into this.

TL;DR
Error occurs when using server actions in NextJS with appwrite due to an issue with isomorphic-form-data library. Developer @antho1404 found a solution by overriding the library with a dummy file using Webpack. This workaround involves creating a form-data-mock.js in the root to fix the error. A permanent fix in future versions to address this import issue would be beneficial for the community.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more