-
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
NestJS generator not working properly #28910
Comments
I'm having the same problems with the paths when using the @nx/nest generators, and I can't really remember a time when this worked properly. I think it worked as you'd expect when you could still use inferred paths, but as far as I can remember it's never worked with explicit paths. Unless I'm misreading things, you don't actually need to use "--path", but can just specify the path as the first argument to the generator (the schema-file for all the generators I've looked at shows it as defaulting to the first argument you specify). Not that it matters though, it still doesn't work. Here are some examples I've been struggling with, mostly for the resource generator, but I've tried others (not all though) and the problems seems to be either the same or similar for all of them. The path I specify has to begin with
Then when I specify a proper path, it goes ahead and screws it up completely - it's basically seeing double:
Also, it doesn't seem to care about the name as much as you'd expect. If I don't put it in the path, it'll ignore it:
If I put a different directory name than the name of the resource, it'll also ignore the name and go with the directory as name.
If I don't specify the name at all, it will ask me to specify it, and then it goes ahead and ignores it completely:
Lastly, if I also don't specify the final directory and don't specify the name, it'll still ask me to specify the name, and then it dies horribly:
|
Hi, @NorseJedi. I encountered all of the problems you mentioned, and it's frustrating. It doesn't matter that you don't remember a time when it was able to work properly, I still remember it, at least on the nx 19, and it still works. In one of my old repositories I was still stay on nx 19 until I created an experimental project using nx 20 and everything broke.
Back then, I used commands like:
Of course, I'm using the As-provided pattern, so it generates:
No misplaced paths, no duplicate paths, no weird nested folders, everything is fine. |
@bzp2010 You're right, it did work in v19, and also in v18 (I just tested them both). I clearly misremembered, I just remember I struggled a lot with getthing this right for both NestJS and Angular, but now I can't figure out why that was... Anyway, it's still broken in v20, and hopefully it's an easy thing to fix :) |
Hi @NorseJedi @bzp2010 yeah, that's easy peazy 👍 Will arrive in around 1-2 hours |
@pawel-twardziak @ndcunningham Thanks for the quick fix. 🫡 But I still have questions about the generators mentioned in the issue |
Hi @bzp2010, let me go through the |
I am not it @bzp2010 :) might be I will answer your question tomorrow cause I have had a bit lazy weekend - need to rest from my computer a bit. |
Hi @bzp2010 👋 sorry for keeping you waiting. It seems like you are right and the code generators for nestjs work weird (apparently the generators and the docs don't match) - create a spearate issue please and I will work on it (if only I could get mentioned there 😆). You can simply And thank you @bzp2010 for your vigilance ❤ |
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
Current Behavior
When using the nx g @nx/nest:service generator, it always reports an error, and the file cannot be generated properly. Check the error log, it seems to indicate that the
path
value is empty.Referring to some of the other nestjs generators, it seems to me that it is missing a
--path
parameter, and if I try to enter it, nx will point out that this parameter is not in the schema.Indeed, https://github.com/nrwl/nx/blob/master/packages/nest/src/generators/service/schema.json
And, it actually worked when I added path to the jsonschema specification. But this still has some other problems, and I mentioned it at the end of the issue.
Expected Behavior
It should normally generate a typescript file.
GitHub Repo
No response
Steps to Reproduce
Nx Report
Failure Logs
Package Manager Version
pnpm 9.9.0
Operating System
Additional Information
In addition to that, I would kindly ask you to indicate the correct way to use the nestjs generator, as it is very different from the way I used it during nx 16-18.
I know we've switched to the default as-provided, but it also looks like the nestjs generator doesn't support directory but uses path instead.
I've read https://nx.dev/deprecated/as-provided-vs-derived#generate-paths-and-names-asprovided, but it doesn't look like that's what actually works, which I don't understand.
For example, when I try to generate code for a project in the root directory, I use the --path option and the files are generated in the wrong path.
It is duplicated in the
apps/my-workspace/src
section and I have to move it manually which I think might be wrong, it should be able to work correctly, in the past I used--directory
to deal with the problem directly, but now it seems that it no longer exists.I saw that section included in
--path
and maybe it was the cause of the error, so I went into that folder and generated it again.Now, the generated path is correct, but again, I noticed that the generated file names
app.guard.ts
and classesAppGuard
in them do not follow the input valueauth
, but appear to be automatically inferred from the pathapp
. It's not just guard, but other nestjs code generators have similar problems, such as controllers and filters.If I want to make sure the filename is correct, I have to make sure that the last part of the path in
--path
is the filename prefix I want. Just like:But unfortunately the two methods above fall back into the cycle of problems about paths mentioned above.
It looks like I have to enter the
app
directory to generate the file atauth/auth.guard.ts
.This breaks the intuition of the previous generator's use of
--directory
, and--path
forces me to infer where I should be generating files and return the up-level directory in that location.Also, I don't want to place the generated files inside a directory, well, at least not every time, e.g. I want to generate
auth.guard.ts
instead ofauth/auth.guard.ts
, which, if memory serves me correctly, was the behavior when I used --directory before.I ask you to show me the right way. Can I generate the code in the root directory by specifying the path? Should the name specified via --name be used as the filename and class name? How to correctly infer
--path
, or restore--directory
behavior?The text was updated successfully, but these errors were encountered: