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.

Bug in firestore: Cannot read property 'replace' of undefined

See original GitHub issue

Version info

DEBUG: -------------------------------
DEBUG: Ember      : 3.18.1
DEBUG: Ember Data : 3.18.0
DEBUG: Firebase   : 7.0.0
DEBUG: EmberFire  : 3.0.0-rc.6
DEBUG: -------------------------------

I am trying to save a sample record in the following way (record gets saved but throws an error):

const game = this.store.createRecord('game', {
      id: Math.round(date.getTime() / 1000),
      has_started: 0,
      is_over: 0,
      player1: 1,
      player2: 2,
      player3: 3,
      player4: 4,
    });
await game.save();

This throws an error :

TypeError: Cannot read property 'replace' of undefined
    at Cache.func (index.js:64)
    at Cache.get (index.js:761)
    at decamelize (index.js:167)
    at Cache.func (index.js:32)
    at Cache.get (index.js:761)
    at Object.dasherize (index.js:190)
    at normalizeModelName (-private.js:62)
    at detectMerge (-private.js:648)
    at IdentifierCache.updateRecordIdentifier (-private.js:456)
    at Store.didSaveRecord (-private.js:8724)

Model app/models/game.js

import Model, { attr } from '@ember-data/model';

export default class GameModel extends Model {
  @attr('boolean') hasStarted;
  @attr('boolean') isOver;
  @attr() player1;
  @attr() player2;
  @attr() player3;
  @attr() player4;
}

Adapter app/adapters/application.js

import FirestoreAdapter from 'emberfire/adapters/firestore';

export default FirestoreAdapter.extend({
});

Serializer app/serializers/application.js

import FirestoreSerializer from 'emberfire/serializers/firestore';

export default class ApplicationSerializer extends FirestoreSerializer {
}

This is reproducible with the bare minimum configuration.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
charlesfriescommented, Jun 30, 2020

^ And for the Firestore serializer:

import FirestoreSerializer from 'emberfire/serializers/firestore';

export default class ApplicationSerializer extends FirestoreSerializer {
  normalizeCreateRecordResponse(_store, _primaryModelClass, payload, id, _requestType) {
    return { data: { id: id || payload.doc.id, attributes: payload.data, type: _primaryModelClass.modelName } };
  }
}
1reaction
zoltan-nzcommented, Jun 11, 2020

@bnetter @mattmcginnis @lalitindoria You can use this patch in your app to keep it working again: https://github.com/firebase/emberfire/pull/600#issuecomment-586595784

./app/serializers/application.js

import RealtimeDatabaseSerializer from 'emberfire/serializers/realtime-database';

export default class ApplicationSerializer extends RealtimeDatabaseSerializer {

  // eslint-disable-next-line no-unused-vars
  normalizeCreateRecordResponse(_store, _primaryModelClass, payload, id, _requestType) {
    return { data: { id: id || payload.ref.key, attributes: payload.data, type: _primaryModelClass.modelName }};
  }
}

You can find an implementation here as well: https://github.com/zoltan-nz/library-app/blob/master/app/serializers/application.js

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug in firestore: Cannot read property 'replace' of undefined
TypeError : Cannot read property 'replace' of undefined at Cache.func (index.js:64) at Cache.get (index.js:761) at decamelize (index.js:167) ...
Read more >
Firebase Function: TypeError: Cannot read property 'replace ...
The error your getting is caused by the body being undefined , so try checking for error before sending back a response:
Read more >
Typeerror: Cannot Read Property 'Replace' Of Undefined ...
JavaScript TypeError is thrown when an operand or argument passed to a function is incompatible with the type expected by that operator or...
Read more >
typeerror: cannot read property 'location' of undefined jest
the ESLint error ESLint: Cannot read property 'replace' of undefined will occur (usually two times). Note: this seems to be new-ish behavior, though...
Read more >
Firebase to Google Sheets Error: Cannot read properties of ...
Current facing the below error when setting up Firebase to Google Sheet. Cannot read properties of undefined (reading 'rest').
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