samedi 9 mai 2015

Unable to import a helper's function in Ember-CLI after 0.2.3 update

After updating Ember-CLI on my project from 0.2.0 to 0.2.3 I find myself to be unable to import any helper-generated functions to any other file.

I created a new project to test it, here's how I tried.

ember -v                                        
version: 0.2.3
Could not find watchman, falling back to NodeWatcher for file system events.
Visit http://ift.tt/1OvndU1 for more info.
node: 0.12.2
npm: 2.7.6

  1. Created a new app with: ember new my-app
  2. After the app was created, I created a new helper with ember g helper test-helper and made its function only return the text test, like so:

    import Ember from 'ember';
    export function testHelper(params/*, hash*/) {
      return 'test';
    }
    
    

    export default Ember.HTMLBars.makeBoundHelper(testHelper);

  3. Edited the app/templates/application.hbs to call the new test-helper like so:

    <h2 id="title">Welcome to Ember.js</h2>
    
    {{test-helper}}
    
    

Up to this point, everything works well, the text "test" shows up under the header on the index page when running ember server and visiting the correct URL.

  1. Create a controller for application using ember g controller application
  2. Import the helper's function to this new controller and set a computed property on it by calling that controller like this:

    import Ember from 'ember';
    import testHelper from 'my-app/helpers/test-helper.js';
    
    export default Ember.Controller.extend({
        helperText: function () {
            return testHelper();
        }.property()
    });
    
    
  3. Made app/templates/application.hbs display the new property by placing {{helperText}} inside it
  4. Ran ember server, it did not complain in any way other than having an unused variable params.
  5. Visit Ember's URL, I receive this error:

    Error while processing route: index Could not find module `my-app/helpers/test-helper.js` imported from `my-app/controllers/application` Error: Could not find module `my-app/helpers/test-helper.js` imported from `my-app/controllers/application`
    
    

I've also tried using a single-word helper (simply test), but that changed nothing. I created a new project just to confirm this is either a bug or something I am doing incorrectly and not an issue with my current project.

The unchanged code from my project worked in the 0.2.0 version of ember-cli but simply downgrading it using npm seems to trigger another error (and I wish to keep ember-cli updated anyway).

I've tried Googling but found no similar results.

So, is there any way to include a helper's function like I could in the past or has this behaviour been replaced with something else? Am I doing something wrong, and if so, what?

Thanks.




Aucun commentaire:

Enregistrer un commentaire