lundi 28 décembre 2020

Error "str.replace is not a function" when using store.queryRecord with Ember Octane

I'm following an Embercasts course (Ember + Rails). For the screencasts, they used Ember 3.0, but I'm using Octane.

In one video, a custom service is implemented. This is what my version looks like:

import Service, { inject as service } from '@ember/service';

export default class CurrentUserService extends Service {
  @service store;

  load() {
    this.store.queryRecord('user', { me: true })
      .then((user) => {
        this.set('user', user);
      })
      .catch((e) => {
        debugger;
      });
  }
}

In the load function, which is being called from a route, this.store.queryRecord() causes an error:

TypeError: str.replace is not a function
  at Cache.func (index.js:64)
  at Cache.get (index.js:774)
  at decamelize (index.js:167) 
  at Cache.func (index.js:32)
  at Cache.get (index.js:774)
  at Object.dasherize (index.js:190)
  at UserAdapter.pathForType (json-api.js:221)
  at UserAdapter._buildURL (-private.js:293)
  at UserAdapter.buildURL (-private.js:275)
  at UserAdapter.urlForQueryRecord (user.js:13)

The relevant line is

var DECAMELIZE_CACHE = new _utils.Cache(1000, str => str.replace(STRING_DECAMELIZE_REGEXP, '$1_$2').toLowerCase());

What's wrong here?




Aucun commentaire:

Enregistrer un commentaire