[question] can not import files nested in a cjs module
I have a module that looks like
the module name is moo
--> index.js (this requires dist/cjs/index.js)
--> dist
--> cjs
--> index.js
--> foo/bar.js
I can not do the following
import Bar from 'moo/foo/bar';
Is this expected?
Yes, this is how all node package resolution works. If you want to be able to import from moo/foo/bar, you really need to name it ./foo/bar.js inside the moo package. Even if you customize main in package.json, that only controls what people get when they import from moo, not what they get when they import moo/foo/bar.
Is there a way to tell ember-auto-import to only import dist/cjs to do this without customizing the package being imported? I tried to use alias but that did not yield the right results.
You can do this with alias but you'll need to do it for each module you are aliasing.
{
autoImport: {
alias: {
"moo": "moo/dist/cjs/index.js",
"moo/foo/bar": "moo/dist/cjs/foo/bar.js",
}
}
}
thank you @ef4!
@ef4 sadly this hasn't worked...It might also be that I am trying to alias a node_module coming from a scoped package? Would this be supported?
It should be supported. You're doing the aliasing in the consuming package, right? Not in moo itself.
yeah, I am doing it at the root level ember-cli-build instead of in the in repo addon that is using it. I will try rebuilding with this option set in the addon itself.