Debuger
Debuger

Reputation: 1

Next.js build error: Module not found: Can't resolve 'fs' when using Edgedb,edgeql-js

I'm encountering a build error in my Next.js application when trying to use Edgedb. The error message I'm receiving is:

  • Build Error

Failed to compile Next.js (14.2.3) ./node_modules/edgedb/dist/adapter.node.js:31:1

Module not found: Can't resolve 'fs'

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module: ./node_modules/edgedb/dist/primitives/buffer.js

./dbschema/edgeql-js/json.ts

./dbschema/edgeql-js/query.ts

./dbschema/edgeql-js/params.ts

./dbschema/edgeql-js/external.ts

I've checked the documentation for both Next.js and Edgedb, but I'm still unsure how to resolve this issue. Additionally, I've tried the following steps:

Reviewed Documentation: I've thoroughly reviewed the documentation for Next.js and Edgedb to ensure I'm following recommended practices and configurations.

Adjusted Webpack Configurations: I've attempted to adjust Webpack configurations in my Next.js project to handle the 'fs' module differently, but so far, I haven't found a configuration that resolves the issue.

Reviewed Dependencies: I've reviewed the dependencies in my project, including Edgedb and any other third-party packages, to ensure they are compatible with Next.js and don't directly or indirectly rely on the 'fs' module.

My expectation is to find a solution that allows me to use Edgedb in my Next.js project without encountering the 'fs' module error during the build process. Specifically, I'm looking for guidance on how to configure Webpack to handle the 'fs' module appropriately in a Next.js environment or alternative approaches to using Edgedb that don't rely on file system operations.

Any help or suggestions would be greatly appreciated. Thank you!

Upvotes: 0

Views: 160

Answers (1)

TheoNeUpKID
TheoNeUpKID

Reputation: 903

If you could bare hearing a little story...

There are a few major advantages in using Nextjs - Unfortunately, if a dependency or peer-depedency thereof rely on Node's Standard Library such as fs its often recommended to substitute said dependency within the Next.config.js via Webpack.

However, as you realized its not always effective the reason being that the dependency may have its own set of dependencies or peer-dependcy there of that require using the Node Standard Library.

I myself was able to bypass this same issue using browser-fs - though, as mentioned there can be some other dependency requiring Node Standard Library or the output could be diff type.

Ultimately, I was able to research and find that the library I was attempting to use would be called as a service call as part of the front-end component - when actuality the correct usage would be called and used as a server component or a ServerSide. Always learning and testing my knowledge, please let me know if this helps. Thanks

Upvotes: 0

Related Questions