-
-
Notifications
You must be signed in to change notification settings - Fork 102
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
UNRESOLVED_IMPORT
warning when importing libs from the same Nx workspace
#52
Comments
My current workaround is to |
I also found out that even though |
Here's a minimal reproduction. Run |
It seems that path mappings are not supported out of the box by the stencil compiler which is afaik using rollup under the hood. There are dedicated Rollup plugins for that issue: https://github.com/bitshiftza/rollup-plugin-ts-paths However, in context of Nx we have the additional challenge, that the app is built with If the Rollup plugin uses the root config, the root path does not match the app path and the module resolution fails. My goal is to get it running with the standard setup, but if you're open to managing the mappings yourself, if may work if you pass the path mappings directly to the plugin: https://github.com/Mutefish0/rollup-plugin-typescript-path-mapping/blob/master/index.js#L22 |
I spent the afternoon on a PR for
Which means that path mappings that reference the
Also, I'm not even sure if a rollup plugin is the actual solution for our problem, as this comment in the Stencil issues suggests, that the Stencil compiler should be able to handle path mappings on its own 🤔 Maybe this is a Windows issue? EDIT: I found the PR that adds path mapping support ionic-team/stencil#1584 |
@luchsamapparat thank you for sharing your investigation! FWIW I'm on Mac OS. I found that the changes introduced in the PR you mentioned were subsequently removed in this PR which has a lot of changes but very little context and has something to do with removing the legacy compiler. I don't know if they were incorporated into another file because it's a large PR. |
I did a quick check yesterday and created a new project with |
@luchsamapparat thanks for your help. Sorry for the late response, I'm at holidays right now. |
@DominikPieper no problem, enjoy your holiday :) @luchsamapparat I'm not seeing an issue with paths like your example. It's when the path is pointing to a build dir, e.g. I did the same quick check using I haven't tried using |
@hnipps Ah, then Stencil probably didn't implement the module resolution, that TypeScript is perfoming, which is quite complex: https://github.com/microsoft/TypeScript/blob/2c08affa0d0d7fc55f15ab22e0326b93326d21d8/src/compiler/moduleNameResolver.ts#L927 When pointing to a path, the compiler not only looks for a Maybe it's worth an issue in Stencil...? EDIT: the problem is probably somewhere here: |
Okay, now I'm back and looked into this. I'll do some experiments as well. The ugly/fastes solution could be using rollup again to bundle the libs. The @nrwl/web plugin does this, cause you can request the dependency tree und bundle up then. I'll try some more with the stencil compiler but maybe that's an workaround |
Hey guys, finally I had some time to investigate deeper into this. Right now I try to find a solution for buildable libs. Trying with stencil 2.0 (maybe something fixed in the meantime) if I export the components I want to use in the libraries index.ts instead of the generated components.d.ts file it works ootb. I'll change the default template for not buildable libraries I think, to work here like the angular builders. |
Unfortunately, the new version brings in a half solution—there a now the concept of buildable and not buildable libraries like in the Angular plugins. Import from not buildable plugins works well (just typescript doing some work here) but buildable libs, there's not a solution yet :-( |
i was able to solve this by updating paths in tsconfig.base.json to this: "paths": {
"@cool-app/component-a": ["dist/libs/component-a/dist"],
"@cool-app/component-b": ["dist/libs/component-b/dist"],
"@cool-app/component-c": ["dist/libs/component-c/dist"],
"@package": ["package.json"]
} and by importing the packages in the global script: import '@cool-app/component-a';
import '@cool-app/component-b';
import '@cool-app/component-c';
export default async () => {
/**
* The code to be executed should be placed within a default function that is
* exported by the global script. Ensure all of the code in the global script
* is wrapped in the function() that is exported.
*/
}; it feels wrong, but it works and doesn't appear to break the dependency graph |
I have a Nx workspace with 1 app and 6 libs (4 of which were generated using
@nxext/stencil
):MainLib is dependent on LibA and LibB.
When building MainLib I get this error for both LibA and LibB:
There are no inline errors in
component-map.ts
and mytsconfig.json
paths
property looks like this:I'm pointing the lib paths to
dist/
because they're publishable.I feel like this is a
node-resolve
issue but I haven't had any success debugging it so far.The text was updated successfully, but these errors were encountered: