Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use firebase-admin + adapter-node (cannot be made external) #7216

Closed
CaptainCodeman opened this issue Oct 10, 2022 · 6 comments · Fixed by #7311
Closed

Unable to use firebase-admin + adapter-node (cannot be made external) #7216

CaptainCodeman opened this issue Oct 10, 2022 · 6 comments · Fixed by #7311
Labels
bug Something isn't working pkg:adapter-node
Milestone

Comments

@CaptainCodeman
Copy link
Contributor

Describe the bug

Trying to use adapter-node with firebase-admin has been broken since the switch from esbuild to rollup (pinning to v92 of adapter-node works).

With the pinned version, the firebase-admin imports are retained in the server chunks, e.g.

import { initializeApp } from "firebase-admin/app";

But with any version after that, the firebase package is bundled in to the server code (but incorrectly, which causes an error).

The symptom is the error below, but the issue is really that firebase-admin is being bundled in no matter what.

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'string_decoder' imported from /Users/simon/dev/thread-bare/experiment/build/server/chunks/2-2a51a21d.js
    at new NodeError (node:internal/errors:393:5)
    at packageResolve (node:internal/modules/esm/resolve:860:9)
    at moduleResolve (node:internal/modules/esm/resolve:909:20)
    at defaultResolve (node:internal/modules/esm/resolve:1124:11)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:837:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
    at link (node:internal/modules/esm/module_job:75:36)

Reproduction

https://github.com/CaptainCodeman/svelte-kit-firebase-admin-external

Logs

No response

System Info

System:
    OS: macOS 12.6
    CPU: (6) x64 Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz
    Memory: 1.68 GB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.10.0 - ~/Library/pnpm/node
    npm: 8.19.2 - ~/Library/pnpm/npm
  Browsers:
    Brave Browser: 102.1.39.111
    Chrome: 106.0.5249.91
    Chrome Canary: 108.0.5351.0
    Firefox: 105.0.1
    Safari: 16.0
    Safari Technology Preview: 16.4
  npmPackages:
    @sveltejs/adapter-node: next => 1.0.0-next.96 
    @sveltejs/kit: next => 1.0.0-next.512 
    svelte: ^3.44.0 => 3.51.0 
    vite: ^3.1.0 => 3.1.7

Severity

blocking an upgrade

Additional Information

I tried to "server module" all the things, and also set thing to external in vite.config.js, but nothing seems to prevent it being bundled in. I've also tried changing it to be a devDependency (which I think would be incorrect, but was clutching at straws).

@leroytromp
Copy link

I can confirm reproduction of this bug. This is a severe bug that makes deployment of adapter-node apps that use firebase-admin impossible. I also have had no luck in my search for a workaround.

@gbkwiatt
Copy link
Contributor

Same issue here as linked above. It bundles things that shouldn't be bundled. And they were not bundled in previous versions of adapter node.

@gbkwiatt
Copy link
Contributor

So it all happened on adapter-node 93 when it was switched from esbuild to rollup. However even going back to 92, gives me Error: Dynamic require of "http" is not supported so it's all broken now and I can't deploy with adapter-node.

@gbkwiatt
Copy link
Contributor

Also looks like, in my case it's because monorepo structure. So project I am building doesn't have any devDependancies or dependancies (dependancies only have workspace dependency).
So it just bundles everything. If I add module in that project to dependancies it does not get bundled.
However it's a regress, as that was working fine before going to rollup.js.
So maybe there is better way to resolve dependencies, and account for mono repo structure ?

@gbkwiatt
Copy link
Contributor

This is not fixed in my case. When there is dependancy in root package.json in monorepo in non dev dependancy, it's still being bundled. I have to add it to package/app package.json into dependancies for it to be not bundled

@dummdidumm
Copy link
Member

I'd argue this is the right thing to do anyway in my opinion - each package in a monorepo should explicitly list its dependencies, even if that means some packages list the same dependencies over and over.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pkg:adapter-node
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants