firebase / firebase/apphosting-adapters

Firebase hosting emulator is somehow loading 'firebase' module from root node_modules

Open
#64 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
478
Forks
1.5k
Avg merge
3d 22h
Merged PRs (30d)
2

Description

I've noticed pretty weird behavior when using webframeworks.
I have `firebase@8` package in my client code, but when I'm starting Firebase Hosting emulator for my Next.js app and navigating to any non-existing page, Im getting an error:
```
[hosting] Rewriting /ss to http://127.0.0.1:5001/fir-next-ad843/us-central1/ssrfirnextad843 for local Function us-central1/ssrfirnextad843
i functions: Loaded environment variables from .env.
i functions: Beginning execution of "ssr"
⚠ functions: Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/Volumes/Work/git/firebase-next/node_modules/firebase/app' is not supported resolving ES modules imported from /Volumes/Work/git/firebase-next/.firebase/fir-next-ad843/functions/node_modules/firebase-frameworks/dist/firebase-aware.js
Did you mean to import firebase-next/node_modules/firebase/app/dist/index.cjs.js?
at new NodeError (node:internal/errors:399:5)
at finalizeResolution (node:internal/modules/esm/resolve:319:17)
at moduleResolve (node:internal/modules/esm/resolve:945:10)
at defaultResolve (node:internal/modules/esm/resolve:1153:11)
at nextResolve (node:internal/modules/esm/loader:163:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
at ModuleWrap. (node:internal/modules/esm/module_job:77:40)
at link (node:internal/modules/esm/module_job:76:36)
⚠ Your function was killed because it raised an unhandled error.
```

A quick investigation has shown, that it seems firebase-frameworks mistakenly trying to load firebase/app from my root node_modules, instead of using .firebase/node_modules, as updating my root package to v9 helped (but I can't use it for now so need to find another solution)

~I wonder, if this may be related to using `source: '.'` in my firebase.json?~
(checked with nested folder, failed again)

**UPD**: this also leads to error when trying to deploy:
```
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: firebase-frameworks@0.6.2
npm ERR! Found: firebase@8.10.1
npm ERR! node_modules/firebase
npm ERR! firebase@"8" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peerOptional firebase@"^9.9.0" from firebase-frameworks@0.6.2
npm ERR! node_modules/firebase-frameworks
npm ERR! firebase-frameworks@"^0.6.0" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: firebase@9.17.1
npm ERR! node_modules/firebase
npm ERR! peerOptional firebase@"^9.9.0" from firebase-frameworks@0.6.2
npm ERR! node_modules/firebase-frameworks
npm ERR! firebase-frameworks@"^0.6.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
```

This may be also related to my prev issue: #63

Fresh repo for reproducing: https://github.com/alekseykarpenko/firebase-next

Env:
node: v16.19.0 (tried on 18 as well)
firebase-tools: 11.22.0

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.