question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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).

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
dummdidummcommented, Oct 19, 2022

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.

1reaction
gbkwiattcommented, Oct 17, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot use import statement outside a module - Firebase with ...
It seems that your function is not defined as being a module so you can't use import inside of it. You'll have to...
Read more >
Firebase Database REST API
New databases are created with defaultWriteSizeLimit set to large . You can't set defaultWriteSizeLimit to tiny using the Firebase CLI.
Read more >
import fetch from "node-fetch"; ^^^^^^ syntaxerror: cannot use import ...
Fetch 3.0 is designed for using esmodules instead of commonjs. Therefore you have to make sure you import it into a module.
Read more >
Getting data | Firestore - Google Cloud
... try restarting your device. Your browser can't play this video. ... Bulk-load Firestore snapshot data from an external source via data bundles....
Read more >
How to fix error TS7016: Could not find a declaration file for ...
Sometimes the types might not be available and the npm install command fails. In that case, you can use the second option and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found