-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Cannot find all references to shared lib's interfaces in VS Code #3106
Comments
Just stumbled upon this a few minutes ago. :-( |
Thanks for posting this @andriychuma. I attempted your suggested workaround and had success with utilizing "Find all references" again. I'm curious though, do the typescript settings need to be made in each lib? I was able to make the change in the root tsconfig and it seems to work. It seems like this should be fine since all of the individual lib tsconfig files inherit from the root right? |
Well, I noticed that changing this value at the root level does fix the "Find all references" issue, but it breaks lots of other things with imports, so it seems that you are correct that it would have to be done in all libs. Suppose I will have to spend a bit more time understanding the fix. Thanks again for posting though. |
Hello, I have this problem in my application based on monorepo nx my example looks like this first case
second case
third case I think the problem is this example is at: |
Yes @amayer42 , it looks like the composite flag should be introduced for libs only. Workaround for NX 10
Before
After
From now on, all the monorepo projects are automatically discoverable by TS server and you can find usages/refactor library's interfaces in VS Code. Works in the following environment
|
Thanks @andriychuma Thank you for your help... When you turn on references you shoud add to tsconfig.lib.json all files that your library depends on Maybe you know a better way than to add all the imported files to tsconfig so that renaming works? |
@Areen3 , I see you made your apps composite by extending |
sugested by andriychuma nrwl/nx#3106 (comment)
Dear @andriychuma , I just stumbled upon the exact same issue, however, in another context: I noticed, that my VSCode was not able to "update imports after renaming" anymore, and i was buffled by this fact.
Then this got me hooked and i was thinking this must be some joke 🤔 I then inspected the When i removed those empty arrays, i got errors, that the other 2 files must have the Adding the latter solved the issue for me - and i can refactor again 😆 Dear @vsavkin , @FrozenPandaz , may someone look into this issue? i can confirm the issue described by @andriychuma as i ran into this issue myself today. It costed me about 5 hours, until i found the solution! All the best |
Dear @andriychuma , thank you for your proposed solution in comment ( #3106 (comment) ), however, this does not work for me (see issue with updating file imports). Do you have, by chance, the same issue? Does your solution work for the latest NX? All the best |
Since the workarounds in this thread do seem to work, but don't compile, at least in Nx 11.0, I made a CLI tool to quickly apply and un-apply them to a workspace: https://www.npmjs.com/package/farp |
I don't recommend that solution to anyone, it is pretty radical, but what I made(tested only on react repos). I deleted all tsconfig*.json files from all dirs and made just one
And then inside of each lib/app new
As a benefit, it also solves #3664 (you can make a type check command that will check types of all your source code. It is good for CI at least) with just one command:
|
NOTE: this is a solution only for NX 11, and as I suppose you may lose upgradeability to the future NX versions |
Hello there, Here is my fix that addresses everything and breaks nothing that I'm aware of. Ping me otherwise. In tsconfig.base.json, add this: {
"includes": ["**/*.ts"]
} Replace the tsconfig.json of every library by: {
"extends": "../../tsconfig.base.json"
} |
Dear @tomtaz , i think, a better solution is as follows:
{
"extends": "../../tsconfig.base.json",
+ // "files": [],
+ "include": ["**/*.ts"],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.spec.json"
}
]
} i.e., comment out the |
Hi @johannesschobel , I tried what you proposed, it does not solve every issue I have.
|
Maybe @vsavkin or @FrozenPandaz can join and provide feedback and maybe a hotfix for |
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. |
Bump |
I was following the tutorial from nx docs and vscode not recognize @myorg/data shared lib, someone had this issue? Thanks! |
This is still an issue 😕 and it really breaks the DX while refactoring code (i.e. I cannot just simply rename properties/methods etc. that might be shared used outside a lib, I have to rely on search & replace to be sure) |
All this modern web-development is pretty sad. On real world project with dozen apps and 50 shared libs VScode is basically acts as text editor, spending seconds each time to understand where to go with ctrl+click, and its not only TS/JS, its same for Angular - also spinning CPU each time you hover something or ctrl+click... @vsavkin just uses IDEA, jetbrains IDEs have no such problems, but they dont have proper NX extension - existing 3rd party one breaks after each update, nowdays for example custom generators not working... There was hope that this exponential grow of VSCode will make it as powerfull as IDEA in few years, but majory of users using it to write Hello-world apps with React and filming Youtube videos - there is just no demand to fix this. I think best option is to switch to become some Unity or Android developer to fix this problem 😁 |
@FrozenPandaz Any updates on this? |
Up ↑ |
1 similar comment
Up ↑ |
@andriychuma is this still an issue? I just stumbled upon this issue and it's making me question whether I should continue to work on integrating nx into my existing repo. If it's going to break TS dev experience (which is already poor without nx) then I'll have to rethink things. |
Seriously? The TS Dev Experience is one of the smoothest in my opinion.. |
@evelant, the issue is not fixed yet, but I don't think it should be a pitfall on your Nx monorepo journey. Even being fixed, it's quite likely you wouldn't avoid additional manual adjustments. A multi-project TypeScript repository with project interdependencies should have a properly configured dependency tree for IntelliSense/TSServer to work properly in VS Code. When you add a new app or lib into your monorepo, Nx CLI doesn't know its future relationships with other apps, that's where manual intervention might be needed. I took the latest Nx v15.2.1 and tried to identify the config adjustments needed for IntelliSense to work fine. There might be some edge cases that I didn't test, but the following tweaks fix the issue. I created a fresh new monorepo and added three projects:
Here's the initial structure of tsconfigs:
Then I tweaked them a little bit and added a solution-like tsconfig in the root folder:
Now if you export an interface from the |
@andriychuma Thanks for the details! I actually ended up using https://github.com/google/wireit with pnpm workspaces and that provides me with everything I need for now. I don't think I really need the extra capabilities of nx at the moment. Wireit does a fantastic job of running my build tasks in parallel with caching and has very simple configuration. FWIW I ended up needing a similar tsconfig setup, nx or not. I think that's just how ts generally ends up needing to be configured to work in a monorepo layout. |
There is a possible gotcha hidden in your project tsconfig.json file that has not been mentioned here. If you have set baseUrl then VS code cannot find your module in libs (typescript error). This results in the problem described.
Remove it and it works again. If you do your internal imports without path navigation
then you will need to add it back in
Hope that helps someone! |
Ran into this problem, and figured out my issue. Context: I'm re-platforming an old Next build to a new Next environment using Typescript and NX, but I have some libraries from the old build with components in regular js/jsx. The solve was updating allowJs to be true, and updating includes to: ["**/*.js"] in my library's ts.config
|
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. |
AFAICT this still hasn't been fixed. |
This still seems like a very pressing issue - if it's not something that can/will be "fixed" by Nx itself, is it possible that a recommended approach to TS config could be published in the docs somewhere so that Nx users making use of VS Code (presumably most of them?) aren't losing core basic Typescript functionality like Rename? How are the Nx team working around this in their projects? |
AN issue is opened here, and we're getting help from the vscode folks on it. microsoft/TypeScript#56268 |
The microsoft/TypeScript#56268 issue got closed ("Working as Intended"). We need some official Nx docs/resource we can follow in order to solve this problem |
Has anyone tried the solution suggested here? https://jakeginnivan.medium.com/using-typescript-project-references-in-nx-b3462b2fe6d4 |
This is still a major issue for me. It is impossible to find consumers of let's say a function that is part of a shared Nx library by using the Has anyone found a solution yet? |
2024-04-15 SOS |
I have a similar issue from test files in an nx/next project. The non-spec files can find the lib at it's tsconfig path but not spec files... |
The issue in my case was that the nx/next generated app set up it's -> As soon as I changed it to match other nx generated projects I start to get lib paths being found in spec files i.e. -> Not 100% sure, but it seems to be related to fact the app |
Hello, Any news on this topic ? |
Also a problem for us, lots of import error noise and getting worse, seems silly that after 4 years there is not any nx documentation around this |
Current Behavior
VS Code cannot discover references to shared entities that are defined in an nx lib. E.g. in a fresh new
angular-nest
nx monorepo VS Code cannot find all references to theMessage
interface defined inapi-interfaces.ts
. As a consequence, we cannot rename the entity throughout the workspace.As far as I understood, it happens due to separate Typescript projects we have for apps and libs, and due to the fact, VS Code relies on the Typescript server while identifying references. This issue was described in this Typescript ticket and fixed within this one. It is not reproducible in WebStorm, which perhaps uses another way of reference discovery in a workspace.
That's rather not a bug of
nx
per se, but the initial configuration bug/improvement.Expected Behavior
Find all references and Rename features should work in VS Code throughout all the nx monorepo Typescript subprojects.
To have it working, every nx shared lib should have the following Typescript options enabled:
E.g. in
libs/api-interfaces/tsconfig.json
More details for the
composite
option is described here.Also, we might want to reference lib projects from within application projects. However,
I don't know how beneficial it might be in nx monorepos since it's not required for fixing the current issue.
E.g. in
apps/api/tsconfig.json
:Steps to Reproduce
npx create-nx-workspace@latest test
.angular-nest
.api-interfaces.ts
(this file should be the first and the only file opened after running VS Code).Message
interface via Shift+F12 or Alt+Shift+F12.Actual result: no reference found.
Environment
The text was updated successfully, but these errors were encountered: