knownasilya/ember-toastr

module unification support? / this.get('toast') is undefined

Closed this issue · 15 comments

was trying to use this library, but I get

Error while processing route: setup.introduction Assertion Failed: Attempting to inject an unknown injection: 'service:toast' Error: Assertion Failed: Attempting to inject an unknown injection: 'service:toast'

Edit / Update

not sure what I did to get rid of the service:toast unknown injection issue.

but now this.get('toast') is undefined

Show us your code please.

At the moment the toastr service is automatically injected as toast into controllers, routes, and components.

I was trying to use it in a service.

Code: https://github.com/NullVoxPopuli/emberclear/blob/master/src/services/relay-connection.ts#L47

I had to replace the toasts with console.log to unblock myself

actually, I may have just had a different problem. Closing this while I figure out things.

ok, here we go: @Caltor

export default class ApplicationRoute extends Route {
  relaySocket = service('relay-connection');
  toast = service('toast');

  activate(this: ApplicationRoute) {
    this.get('toast').success('hello');
  }
}

different error than originally, reported, but maybe related?

Error while processing route: login Cannot read property 'success' of undefined TypeError: Cannot read property 'success' of undefined
    at ApplicationRoute.activate (http://localhost:4200/assets/emberclear.js:1536:34)

error happens with and without manual injection
the diff: NullVoxPopuli/emberclear@21845bb#diff-d9845b3542297df7a23a176bb15fc63aR6

Also, to make sure it wasn't an es6 class issue:

export default Route.extend({
  activate() {
    this.get('toast').success('hello');
  }
})

demonstrates the same error.

That last piece of code works fine for me (after import Route from '@ember/routing/route'; obviously) so I think it's config/environment rather than code. Silly question but have you remembered to run bower install and npm install? Might also be worth checking your package.json.

thanks for taking the time to help with this. :-)

my project doesn't use bower, but clearing things out is a good idea. Here is what I did (just now):

rm -rf node_modules tmp dist
yarn install

Same issue :-\

package.json has:

    "ember-toastr": "^1.7.1",
    "toastr": "^2.1.4",

the most recent commit ( NullVoxPopuli/emberclear@abc26a1 ) demonstrates the error if you feel like looking.

as for config/environment, it's pretty basic (haven't done much manually to it)

'use strict';

module.exports = function(environment) {
  let ENV = {
    'ember-resolver': {
      features: {
        EMBER_RESOLVER_MODULE_UNIFICATION: true
      }
    },
    modulePrefix: 'emberclear',
    environment,
    rootURL: '/',
    locationType: 'auto',
    EmberENV: {
      FEATURES: {
        // Here you can enable experimental features on an ember canary build
        // e.g. 'with-controller': true
        'ember-module-unification': true
      },
      EXTEND_PROTOTYPES: {
        // Prevent Ember Data from overriding Date.parse.
        Date: false
      }
    },

    'i18n': {
      defaultLocale: 'en-us'
    },

    APP: {
      // Here you can pass flags/options to your application instance
      // when it is created
    }
  };

  if (environment === 'development') {
    // ENV.APP.LOG_RESOLVER = true;
    // ENV.APP.LOG_ACTIVE_GENERATION = true;
    // ENV.APP.LOG_TRANSITIONS = true;
    // ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
    // ENV.APP.LOG_VIEW_LOOKUPS = true;
  }

  if (environment === 'test') {
    // Testem prefers this...
    ENV.locationType = 'none';

    // keep test console output quieter
    ENV.APP.LOG_ACTIVE_GENERATION = false;
    ENV.APP.LOG_VIEW_LOOKUPS = false;

    ENV.APP.rootElement = '#ember-testing';
  }

  if (environment === 'production') {

  }

  return ENV;
};

my project doesn't use bower

I believe that ember-toastr still uses bower so you don't have a choice.

It's still part of the installation instructions https://github.com/knownasilya/ember-toastr#installation and my request to remove it as a dependency was closed without further action. As far as I know that is still the case.

right, but I just assumed that was left over from the default addon blueprint.
looking at the files,
image
there is no bower.json, so how could it know what to install?

Hmm I'm at a bit of a loss then bud, sorry! I'm still on version 1.5.0 of ember-toastr and it was a dependency back then. Presumably you're on a newer version. Hopefully someone else more knowledgeable can help you out.

"ember-toastr": "^1.7.1",
"toastr": "^2.1.4",

1.7.1 doesn't need bower so it's definitely not that. Another silly question but have you tried rebuilding (e.g. ctrl+c then ember s) after installing the addon? That caught me out when testing earlier. Might also be worth clearing the browser cache - just in case.

so, now that I've truly updated to ember canary (I had an old tgz in my package.json)

npm install --save-dev https://s3.amazonaws.com/builds.emberjs.com/canary/shas/62d6d85deed028f4654dee9bbe89885953042137.tgz

I have it working.

the problem was that I was using a very old canary build.

Thanks for all your help!