Skip to content

In addon: only runs in the dummy app #32

Closed

Description

@ppcano

https://github.com/ppcano/compatibility-helper-addon reproduces the error.

  1. In the dummy app, using ember-compatibility-helpers works and Babel transforms properly the flag of the dummy.js file.
// tests/dummy/app/controllers/application.js

import { gte } from "ember-compatibility-helpers";
import Controller from "@ember/controller";
import { computed } from "@ember/object";

export default Controller.extend({
  gte3: computed(function() {
    return gte("3.0.0");
  })
});
  1. In the addon folder, it triggers the error Uncaught Error: Could not find module ember-compatibility-helpers imported from compatibility-helper-addon/components/test-component
// addon/components/test-component.js

import Component from '@ember/component';
import layout from '../templates/components/test-component';
import { computed } from "@ember/object";

import { gte } from "ember-compatibility-helpers";

export default Component.extend({
  layout,
  gte3: computed(function() {
    return gte("3.0.0");
  })
});

This behaviour looks to be totally different than the one reported at #29, the issue was initially reported at ember-cli/ember-welcome-page#124

Activity

  1. pzuraq commented on Feb 7, 2019

    @pzuraq
    Collaborator

    This is a common issue, you need to move it to your addon’s dependencies instead of devDeps. I wish there was a way to warn people about this, this is true of all addons and I see people run into it all the time 😩

  2. ppcano commented on Feb 7, 2019

    @ppcano
    Author

    @pzuraq You were right with this example, adding the addon to the dependencies solved the issue, however, 🤪🤯 this does not look to solve the issue on the ember-welcome-page example (the one that I initially found).

    The error is reproduced at
    ember-cli/ember-welcome-page#127 (CI job shows the commented error)

    ember-cli/ember-welcome-page@0c6ec85

  3. pzuraq commented on Feb 7, 2019

    @pzuraq
    Collaborator

    I believe the issue comes from this line here: https://github.com/ember-cli/ember-welcome-page/pull/127/files#diff-168726dbe96b3ce427e7fedce31bb0bcR8

    This is another one of those gotchas that I wish we could teach better. Basically, calling this._super.included(app) binds this to this._super, the addon's parent class, instead of the addon itself. This is bad news bears 😞

    You have to do this instead to bind this correctly:

    this._super.included.call(this, app);
    
    // OR
    this._super.included.apply(this, arguments);
  4. ppcano commented on Feb 7, 2019

    @ppcano
    Author

    👏this is the issue (I would have never found it).

    The guide is documented correctly with:

    this._super.included.apply(this, arguments);

    @pzuraq Thank you!

  5. pzuraq commented on Feb 7, 2019

    @pzuraq
    Collaborator

    It is super counterintuitive - I still regularly do this when setting up a new addon. Hopefully we can fix it in the future!

  6. rwjblue commented on Feb 8, 2019

    @rwjblue
    Member
  7. pzuraq commented on Feb 8, 2019

    @pzuraq
    Collaborator

    Any chance we can just fix it CLI by binding the functions on _super? Should be backwards compatible I think.

    The reason it’s so trolly is it works if you do it wrong, until you have subaddons. Could probably start warning if this is bound incorrectly?

  8. ppcano commented on Feb 9, 2019

    @ppcano
    Author

    I think it may be good to open an issue on the ember-cli repo to avoid forgetting about it (I don't know all the details to describe it accurately).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions