Can't resolve 'fs' in firebase-admin/lib' when using nextjs monorepo project with lerna
Asked Answered
S

2

6

I have a Lerna MonoRepo project setup.

Like

root/
   lerna.json
   packgae.json
   package.lock.json
   packages/
       app1 - Create react app (with firebase sdk dependency)
       app2 - Next Js app (with firebase-admin dependency)
       components - shared react components.

when I try to build next js app then following error occurs.

Blockquote ModuleNotFoundError: Module not found: Error: Can't resolve 'fs' in 'root-project/node_modules/firebase-admin/lib'.

Sabbatical answered 12/8, 2021 at 12:49 Comment(1)
Make sure you only use firebase-admin in server-only code (e.g. getStaticProps, getServerSideProps, API routes).Finished
S
9

firebase-admin package is supposed to run in Node environments, not in browser projects. 'fs' is a built-in Nodejs package.

Sweetening answered 12/8, 2021 at 13:9 Comment(1)
How to fix this issue?Satinet
P
1

Extending on vijayst's answer: You need to use the examples given for 'Web version 9' on de firebase docs. You cannot use firebase-admin on web. You can only use it server-side. You need to use the firebase package

Psychobiology answered 20/9, 2022 at 9:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.