-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
IOC resolve can't import from index.ts, but it's COPY index2.ts is ok. #825
Comments
hey @muyu66 could you show us your module definition ? |
@adrien2p When code "import { UserDao } from './daos/index'", it throw Error. Under these circumstances, I think my module definition is not related to this |
what are your compiler options in your |
I also experienced some really strange behaviour like @muyu66 described. Seems like a bug with the module resolution to me. Do not know if it is a bug of TS or Nest though. |
This is my tsconfig.json
Yes, i try "./dao/index" and "./dao" |
Let us continue to observe whether there are more examples. I cannot unilaterally reproduce |
@adrien2p @BrunnerLivio This problem can be reproduced by "npm run dev" Project is in: (branch is resolve) |
@muyu66 Yup also able to reproduce it. |
I don't understand the internal ioc implementation mechanism of Nestjs, I try to read its source code, still can't understand. I am currently using a solution to circular dependencies to temporarily circumvent this problem. Just use @Inject(forwardRef(() => TestService)), it's can be resolved temporarily. |
I reproduce will investigate a bit |
Thinks, this error is very important to me because I can remove a lot of "forwardRef". |
@muyu66 The thing is that actually the export * from './test2';
export * from './test1'; Tell me if i wasn't clear enough :) |
@adrien2p But are you sure this is the problem? I know for example import sorter for VSCode which sort the imports alphabetically and ignores the dependency of each import. That would break the application, but it still seems to work? |
@BrunnerLivio This problem has been bothering me for a long time. My typescript is 2.9.2, Nestjs Core is 5.0.1 |
@adrien2p I can understand what you mean, but I didn't modify the code as you suggested, because my project is too big to make this adjustment. |
@BrunnerLivio i think but maybe it is another thing, the fact is i never had this issue because a never import from an index file since i am in the same directory, alway from another directory. |
The advantage of import from index.ts this is that when I need to change the file name, or file path, I don't need to change all the files that reference it. I just need to modify index.ts. |
Yes i completely understand i do it as well. Just not in the same directory ^^ Maybe some one else will find a better way to fix that. And if you change the path, it will not be in this index file anymore but in another one. |
@kamilmysliwiec i want to get your help |
I think of a better way to circumvent this problem. Is to create a hard linux link (ln) to the index.ts, then it's ok that import index_symbolic.ts from test.module.ts Branch is in resolve-ok, it's passed |
Honestly, it sounds like a module resolution issue, instead of anything strictly related to Nest. I saw a bunch of similar issues regarding Angular and I don't think there is a well-known solution available already. |
it's sad |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
[x] Bug report
If code is:
It throw a error:
Now we adjust code:
Then everything is right. It's amazing.
File /daos/index.ts
Version
I think it's bug, IOC resolve can't import from index.ts
The text was updated successfully, but these errors were encountered: