Skip to content

Generated helper does not work out of box under Module Unification feature #17556

Closed

Description

@axyxnz

When you run ember generate helper hello-helper, it generates two files (hello-helper.js and hello-helper-test.js under src/ui/components folder.

The content of hello-heper.js is following:

import { helper } from '@ember/component/helper';

export function helloHelper(params/*, hash*/) {
  return params;
}

export default helper(helloHelper);

Above generated code does not work. During runtime, Ember outputs following error in console:
Uncaught Error: Compile Error: hello-helper is not a helper at opcode-compiler.js:294

To make it work, you need to change how helper exports. If you modify hello-helper.js with following code, it works.

import { helper as buildHelper } from '@ember/component/helper';

export function helloHelper(params/*, hash*/) {
  return params;
}

export const helper = buildHelper(helloHelper);

Thanks @NullVoxPopuli for helping me out on Discord to solve this problem. I can update blueprint for helper and submit a PR to fix this if no one is addressing this issue under Module Unification meta issue.

Activity

  1. rwjblue commented on Feb 16, 2019

    @rwjblue
    Member
  2. ppcano commented on Feb 16, 2019

    @ppcano
    Contributor

    Thanks for reporting the issue.

    The helper blueprint creates the same content for both layouts (Classic and MU), it just places the files in different locations. As far as I know, this is correct and helpers should have the same API either for the Classic or MU layout. , or am I missing something?

    @NullVoxPopuli could you provide more info about why this change was needed?

  3. NullVoxPopuli commented on Feb 16, 2019

    @NullVoxPopuli
    SponsorContributor

    I think it's just the convention going forward.
    I wouldn't be able to point to an RFC or anything, but as far as I've known, this has always been required of the octane layout.

    (but to technically answer your question (not sure exactly which aspect you're asking), the template helper resolver thing requires a named helper export

  4. ppcano commented on Feb 17, 2019

    @ppcano
    Contributor

    Thanks, I found #16361 describing the public API.

    The guides should also be updated, I have added a comment at ember-learn/guides-source#460 (comment)


    @axyxnz

    I can update blueprint for helper and submit a PR to fix this if no one is addressing this issue under Module Unification meta issue.

    A PR would be very much welcomed. Please, let me know if you are gonna work on it.

    A possible implementation could be:

    • define a folder blueprints/helper/mu-files with the new content.
    • overwrite filesPath on blueprint/helper/index.js
       filesPath = function() {
        let rootPath = isModuleUnificationProject(this.project) ? 'mu-files' : 'files';
        return path.join(this.path, rootPath);
      };
    
    • Tests run like
    mocha node-test/blueprint/helper-test.js
    
    • In the helper test, add also the new octane tests in app - octane and in addon - octane.

    For reference, look at b0645bd

    The commit duplicates the existing module-unification test with the octane environment.

  5. axyxnz commented on Feb 19, 2019

    @axyxnz
    Author

    @ppcano I never worked on Ember repository so it may take some time for me to implement the solution.

  6. ppcano commented on Feb 19, 2019

    @ppcano
    Contributor

    @axyxnz np, I have lately modified the blueprints, so I can take a stab on it. Just let me know if you want to pass me the issue or need any support (you can reach me in Discord).

  7. ppcano commented on Feb 28, 2019

    @ppcano
    Contributor

    @axyxnz any progress? I am available to fix this issue.

  8. axyxnz commented on Feb 28, 2019

    @axyxnz
    Author

    Hey, sorry. I got busy with work stuff. You can implement the fix as I won't able to get to this issue til this weekend.

  9. ppcano commented on Mar 3, 2019

    @ppcano
    Contributor

    #17689 has fixed it. This issue should be closed.

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