-
Notifications
You must be signed in to change notification settings - Fork 143
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
Support imports
key from package.json (aka subpath imports)
#2284
Comments
it works when you set
afaik, I have not tried setting |
You mean with vite right? May want to edit your reply to be explicit about that because there are a few possible configurations here. If we think the babel based workaround is good enough to recommend I think that seems fine to suggest doing that as a stepping stone before migrating to a vite build, then embroider wouldn’t have to implementing it specifically. That being said, if we say this is a supported feature, I think it’s still suspicious that there is module resolution logic in @embroider/core that isn’t aware of subpath imports. It seems like things like @embroider/vite or the code mods stuff could easily accidentally use that logic and do the wrong thing. |
I think I just confirmed that in a stock On So I don't think there's a todo here for Embroider. A critical thing about our architecture is that we delegate all module resolution to the host environment -- vite or webpack or (in the case of tools like codemods) node itself. So long as that environment supports subpath imports, so do we. |
I think a key point here is that we need to mark this issue as "won't fix" for the current stable embroider. I think that's the confusion that we are facing right now 😞 For what it's worth I have updated the Vite app blueprint today to remove the warning about "don't use this ever for any app" 😂 https://github.com/embroider-build/app-blueprint?tab=readme-ov-file#embroiderapp-blueprint |
This is regarding this feature.
I couldn't find a consolidated place that documents the support status with subpath imports, so this documents my findings.
moduleResolution = bundler
@my-company/frontend
) and components grouped in one or two levels of folders, your could be 4-5 slashes in before actually reaching the part of the path with useful signal.Currently, in my experience:
tsconfig.compilerOptions.path
.@embroider/compat
/webpack, this fails withbug: embroider resolver's meta is not propagating
@embroider/vite
– maybe it does work, but I am not so sure about that. The problem occurs inside@embroider/core
, and to the extent that it still need to use the shared code to reason about the module graph at some point, it seems like things could subtly break.In my case it seems like an acceptable workaround is (in a compat/webpack app) to use babel-plugin-module-resolver to rewrite the import paths before embroider sees it:
I would think this is preferable/more portable than trying to do similar things with webpack config. This will work with standard import statements and
import()
.A quick test seems to suggest that It but not the custom stuff like
importSync()
from@embroider/macros
. I think that is because in a compat build,@embroider/macros
inserts its babel transform at the beginning, so theimportSync()
is rewritten intorequire()
before this babel-plugin-module-resolver sees it. That's probably fine and reliable enough.I couldn't test
import.meta.glob()
because as far as I can tell it hasn't landed in the compat build yet. The babel plugin also has atransformFunctions
option so maybe it can be configured to rewrite those as well if necessary. If babel-plugin-transform-vite-meta-glob is used, I suppose it would work too, as long as that is inserted before this plugin.The text was updated successfully, but these errors were encountered: