Open amiller-gh opened 6 years ago
In general, addons should avoid app.import
and should instead use this.import
which should automatically resolve dependencies relative to the addon itself.
I dont know that I have tests for that though, definitely happy to confirm/deny. Also, it still probably does make sense to support resolveFrom
just to stay consistent...
Could've sworn that I tried this.import
as well – I thought the same thing seeing it try to resolve from parent.root
, but parent
always seemed to be the app, not the addon. Will confirm 👍
Problem
The AMD transform allows users to specify an optional
resolveFrom
. This allows addons to callapp.import
and reference their dependencies instead of resolving all node modules relative to the app.The CJS transform attempts to resolve the file on disk here and here. However, the
resolveFrom
option is never passed – it always tries to resolve fromparent.root
.This results in an error when the CJS transform can't find the module.
Potential Fixes
It doesn't appear that ember-cli passes the
resolveFrom
option to the custom transforms. If we want to enable this use case without changes to ember-cli, the option will need to be passed twice in userland:Otherwise, the
resolveFrom
option can be passed along to custom transforms'processOptions
hook to be made available for use: https://github.com/ember-cli/ember-cli/blob/v3.0.x/lib/broccoli/ember-app.js#L1711Let me know if I'm off base here! Happy to help make these changes if you'd like to move forward with a fix.