Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated output with staticHelpers: true seems invalid #714

Open
mydea opened this issue Mar 8, 2021 · 6 comments
Open

Generated output with staticHelpers: true seems invalid #714

mydea opened this issue Mar 8, 2021 · 6 comments

Comments

@mydea
Copy link
Contributor

mydea commented Mar 8, 2021

Forked this out from stefanpenner/ember-strict-resolver#45

When building an app with strict helpers, I noticed that e.g. require('helper:page-title') would not return the normal module with a default property, but directly return the default export itself (!?). Not sure what exactly is going on, but after some digging I noticed this small difference in output:

With staticHelpers: true

__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */
__webpack_require__.d(__webpack_exports__, 'default ', function () {
  return PageTitle;
});

With staticHelpers: false

__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */
__webpack_require__.d(__webpack_exports__, 'default', function () {
  return PageTitle;
});

Notice the space after default in the first example.

@rwjblue
Copy link
Collaborator

rwjblue commented Mar 8, 2021

That 'default ' string seems wrong to me, but I'm not sure exactly internally where we handle emitting those modules.

@ef4
Copy link
Contributor

ef4 commented Mar 8, 2021

That certainly looks weird, but I will point out that using require to access helpers when staticHelpers is on is highly likely to break.

Right now if you try it after a template has evaluated that uses the given helper, it will work. If you try it before any template that uses the helper evalutes, it will not.

In upcoming releases we will take advantage of ember's template lexical scope and then it will never work -- the helper will never be registered with the runtime AMD loader.

@rwjblue
Copy link
Collaborator

rwjblue commented Mar 8, 2021

@ef4 - This is the resolver resolving the helper (ember-strict-resolver does much much less than ember-resolver for resolution here), is there some override for ember-resolver in these cases?

@ef4
Copy link
Contributor

ef4 commented Mar 8, 2021

No, it does go through the resolver internally. I just mean people shouldn't rely on looking in requirejs.entries themselves.

@rwjblue
Copy link
Collaborator

rwjblue commented Mar 8, 2021

I just mean people shouldn't rely on looking in requirejs.entries themselves.

Yes, totally agreed!

@mydea
Copy link
Contributor Author

mydea commented Mar 9, 2021

Yes, to clarify, that has nothing to do with manually using require(), it has the same output with just a regular app using staticHelpers, even with the default ember-resolver. Only that ember-resolver seems to handle this by also allowing the module returned from require() to be used directly (instead of module['default']), which makes this work, although I am still not sure why that would even work that way...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants