Skip to content

Server side rendering: ReferenceError: IDBIndex is not defined #2530

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

Closed
zd-dalibor opened this issue Jan 13, 2020 · 6 comments
Closed

Server side rendering: ReferenceError: IDBIndex is not defined #2530

zd-dalibor opened this issue Jan 13, 2020 · 6 comments

Comments

@zd-dalibor
Copy link

I'm trying to make the serverside rendering bundle with webpack. And my application using messages sdk:

import * as firebase from 'firebase/app';
import 'firebase/messaging';

My bundle must be self-contained (do not load node module at runtime - everything should be inside bundle).

I'm trying to solve my problem with suggestions from this #1797 using something like this in webconfg to force loading node compatible scripts:

resolve: {
    alias: {
      ['firebase/app']: path.resolve(__dirname, '../node_modules/firebase/app/dist/index.cjs.js'),
      ['firebase/messaging']: path.resolve(__dirname, '../node_modules/firebase/messaging/dist/index.cjs.js'),
      ['@firebase/app']: path.resolve(__dirname, '../node_modules/@firebase/app/dist/index.node.cjs.js'),
      ['@firebase/messaging']: path.resolve(__dirname, '../node_modules/@firebase/messaging/dist/index.cjs.js'),
      ['@firebase/util']: path.resolve(__dirname, '../node_modules/@firebase/util/dist/index.node.cjs.js'),
      ['@firebase/component']: path.resolve(__dirname, '../node_modules/@firebase/component/dist/index.cjs.js'),
      ['@firebase/logger']: path.resolve(__dirname, '../node_modules/@firebase/logger/dist/index.cjs.js'),
      ['@firebase/installations']: path.resolve(__dirname, '../node_modules/@firebase/installations/dist/index.cjs.js'),
    },
    extensions: ['.js', '.ts']
  }

but the problem is in this module @firebase/installations, both browser and node version have reference on idb module (https://www.npmjs.com/package/idb) with code:

proxyRequestMethods(Index, '_index', IDBIndex, [
  'get',
  'getKey',
  'getAll',
  'getAllKeys',
  'count'
]);

So I do not know how to get rid of this.

I em using firebase 7.6.2 version.

@google-oss-bot
Copy link
Contributor

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

@hsubox76
Copy link
Contributor

Messaging actually is not supported in Node (see supported environments table). Can you set up a different entry point for your server rendering bundle that doesn't import it?

@zd-dalibor
Copy link
Author

zd-dalibor commented Jan 14, 2020

@hsubox76 Ok, I solved this problem with dynamic imports:

import('firebase/messaging').then(() => { ... });

@rommelpe
Copy link

Glad to hear that you found a workaround, @zd-dalibor. I am going to close this issue. If you're still experiencing this problem and want to continue the discussion, just leave a comment here and we are happy to re-open this.

@firebase firebase locked and limited conversation to collaborators Feb 14, 2020
@jamesdaniels
Copy link
Member

FYI looks like this is the same as #6042. One major issue with the work around, dynamic imports break tree-shaking. Which is why it's not something we should be advising.

@jamesdaniels
Copy link
Member

jamesdaniels commented Mar 8, 2022

Also we need to figure out a way to ensure that just including the module, even if it's not supported, does not lead to the developer's entire bundle being broken; as isomorphic code is becoming more commonplace. For the Googlers in the thread, check out this doc for a deeper explanation for the issues at hand.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants