Unable to use firebase-admin + adapter-node (cannot be made external)
See original GitHub issueDescribe 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).
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:6 (5 by maintainers)
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.
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.