lundi 25 mai 2020

Emberfire sves to firebase, but I get an error

Whenever I try to save to Firebase, I get this error, BUT THE DATA IS SAVED:

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

I tried catching it with .catch() after the .then(), but I get the exact same error message.

I am following the tutorial on https://yoember.com/#lesson-3 , but it is not up-to-date, so I am having to figure somethings myself.

The versions of what I am using are in the package.json file bellow.

package.json

{
  "name": "library-app",
  "version": "0.0.0",
  "private": true,
  "description": "Small description for library-app goes here",
  "repository": "",
  "license": "MIT",
  "author": "",
  "directories": {
    "doc": "doc",
    "test": "tests"
  },
  "scripts": {
    "build": "ember build --environment=production",
    "lint:hbs": "ember-template-lint .",
    "lint:js": "eslint .",
    "start": "ember serve",
    "test": "ember test"
  },
  "devDependencies": {
    "@ember/jquery": "^1.1.0",
    "@ember/optional-features": "^1.3.0",
    "@glimmer/component": "^1.0.0",
    "@glimmer/tracking": "^1.0.0",
    "babel-eslint": "^10.0.3",
    "broccoli-asset-rev": "^3.0.0",
    "ember-auto-import": "^1.5.3",
    "ember-cli": "~3.16.2",
    "ember-cli-app-version": "^3.2.0",
    "ember-cli-babel": "^7.17.2",
    "ember-cli-bootstrap-sassy": "^0.5.8",
    "ember-cli-dependency-checker": "^3.2.0",
    "ember-cli-eslint": "^5.1.0",
    "ember-cli-htmlbars": "^4.2.2",
    "ember-cli-inject-live-reload": "^2.0.2",
    "ember-cli-sass": "^10.0.1",
    "ember-cli-shims": "^1.2.0",
    "ember-cli-sri": "^2.1.1",
    "ember-cli-template-lint": "^1.0.0-beta.3",
    "ember-cli-uglify": "^3.0.0",
    "ember-data": "~3.16.0",
    "ember-export-application-global": "^2.0.1",
    "ember-fetch": "^7.0.0",
    "ember-load-initializers": "^2.1.1",
    "ember-maybe-import-regenerator": "^0.1.6",
    "ember-qunit": "^4.6.0",
    "ember-resolver": "^7.0.0",
    "ember-source": "~3.16.0",
    "ember-welcome-page": "^4.0.0",
    "emberfire": "^3.0.0-rc.6",
    "eslint-plugin-ember": "^7.7.2",
    "eslint-plugin-node": "^11.0.0",
    "firebase": "^7.14.5",
    "loader.js": "^4.7.0",
    "qunit-dom": "^1.0.0",
    "sass": "^1.26.5"
  },
  "engines": {
    "node": "10.* || >= 12"
  },
  "ember": {
    "edition": "octane"
  }
}

This is my Model generated with

ember g model invitation email:string

invitation.js

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

export default class InvitationModel extends Model {
  @attr('string') email;
}

The whole index.js is bellow, but the important part I believe is only the @action

index.js

import Controller from '@ember/controller';

import { action } from '@ember/object';
import { match, not } from '@ember/object/computed';

export default class IndexController extends Controller {

  emailAddress = '';
  responseMessage = '';
  headerMessage = 'Coming Soon';

  @match('emailAddress', /^.+@.+\..+$/)
  isValid;

  @not('isValid')
  isDisabled;

  @action
  saveInvitation() {
    const email = this.emailAddress;

    const newInvitation = this.store.createRecord('invitation', { email: email });

    newInvitation.save()
    .then(response => {
      this.set('responseMessage', `Thank you! We saved your email address with the following id: ${response.get('id')}`);
      this.set('emailAddress', '');
    })
    .catch(error => {
      console.log(error);
    })

  }

}

The closest issue / question I found to this error message is this (The same error message, but we run into them quite differently): https://github.com/emberjs/data/issues/5811

But didn't help me understand what is going on here.




Aucun commentaire:

Enregistrer un commentaire