kossnocorp / typesaurus

🦕 Type-safe TypeScript-first ODM for Firestore
https://typesaurus.com
415 stars 34 forks source link

How to use `firebase` package in NodeJS? #49

Closed hotchpotch closed 4 years ago

hotchpotch commented 4 years ago

I use typesaurus with Next.js that is working on NodeJS and browser.

When typesaurus use with Next.js, require firebase-admin. I want to use only firebase package.

Do you know how to use firebase package in NodeJS (or Next.js)?

kossnocorp commented 4 years ago

I want to use only firebase package.

Hey! I'm not quite sure how Next.js works, and I'm not familiar with using firebase in Node.js, but I doubt it will work.

Could you please tell me more about your use case so I can understand better how I can help?

hotchpotch commented 4 years ago

Hi!

I created example.

git clone https://github.com/hotchpotch/next-with-typesaurus-example
cd next-with-typesaurus-example
yarn install
cp  firebase.config.js.example  firebase.config.js
# replace settings: firebase.config.js
yarn dev
open http://localhost:3000/

raise error...

[ ready ] compiled successfully - ready on http://localhost:3000
{ Error: Cannot find module 'firebase-admin'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)

If changed ./node_modules/typesaurus/adaptor/package.json

{
  "browser": "./browser/index",
  "main": "./browser/index"
}

This is working. So I want use firebase package on Node.js.

kossnocorp commented 4 years ago

I got you! I'm looking into it.

kossnocorp commented 4 years ago

@hotchpotch, unfortunately, I can't provide a proper fix for you because of a Next.js bug: https://github.com/zeit/next.js/issues/12633

I would appreciate it if you can chime in into the issue.

In meanwhile you can use a workaround I've sent you in a PR: https://github.com/hotchpotch/next-with-typesaurus-example/pull/1. I also recommend using Typesaurus React 😉

hotchpotch commented 4 years ago

wow, great. Thank you very much! 😄

and I'll try to use TYpesaurus React right away!

kossnocorp commented 4 years ago

You're welcome!