Skip to content
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

Nestia can not properly find @nestia/sdk in Yarn Monorepos #251

Closed
Aderinom opened this issue Feb 19, 2023 · 10 comments
Closed

Nestia can not properly find @nestia/sdk in Yarn Monorepos #251

Aderinom opened this issue Feb 19, 2023 · 10 comments
Assignees
Labels
bug Something isn't working

Comments

@Aderinom
Copy link

Aderinom commented Feb 19, 2023

Bug Report

Summary

Nestia can not find it's packages when beeing used in a yarn monorepo

  • SDK Version: 1.0.7 (skipped installing the @next version since I took a look at the current source code)
  • Expected behavior:
    npx nestia swagger "src/**/*.controller.ts" --out ./
    should output a swagger.json
  • Actual behavior:
    @nestia/sdk has not been installed. Run "npx nestia setup" before.

Nestia tries to find its packages by using a fully qualified path:

await import(process.cwd() + "/node_modules/@nestia/sdk"); index.ts:53

This does not work as expected in yarn monorepos and will probably also cause issues with
repos using pnpm.

Yarn saves all packages from child workspaces in the root node_modules. (hoisting)
As such the fully qualified path supplied will not be able to find the packages.

Example format of yarn monorepo

/app
  /server
     app.ts
     package.json (has @nestia/sdk as a dependency)
     ...
/lib
  ...
/node_modules
   /@nestia/sdk
   /...
/package.json (could in theory also have the @nestia/sdk as a dependency, making it "global" at least in my understanding)
@Aderinom Aderinom changed the title Yarn Monorepos can not find @nestia/sdk Nestia can not properly find @nestia/sdk in Yarn Monorepos Feb 19, 2023
@samchon
Copy link
Owner

samchon commented Feb 20, 2023

OK, I'll patch it after home.

@samchon samchon self-assigned this Feb 20, 2023
@samchon samchon added the bug Something isn't working label Feb 20, 2023
@samchon
Copy link
Owner

samchon commented Feb 20, 2023

package.json also exists in ./ path?

@Aderinom
Copy link
Author

Aderinom commented Feb 20, 2023

Updated the example layout.

But yes, there is always a package.json in the root path. At least with yarn and pnpm.
I'll quickly make an example repo.

@samchon
Copy link
Owner

samchon commented Feb 20, 2023

Okay, I will wait for

@Aderinom
Copy link
Author

There you go. Installed nestia manually with ttsc.
Server works as expected. CLI fails to find nestia.

https://github.com/Aderinom/yarn-monorepo-example

When I tried to use the nestia setup yesterday, that also ran into some issues, don't remember what though.

@samchon
Copy link
Owner

samchon commented Feb 20, 2023

I'll try it, thx.

@samchon
Copy link
Owner

samchon commented Feb 20, 2023

Oh my god, I found that node_modules directories are generated in both ./ and ./apps/nest.

I have to check both of them.

@Aderinom
Copy link
Author

I'm not sure. But I think that require would actually try all node_modules in all parent folders.
Sadly I have to be somewhere right now else I'd try to find some info on how other cli tools solve this / how resolve works for modules. .

@Aderinom
Copy link
Author

However, resolution for a non-relative module name is performed differently. Node will look for your modules in special folders named node_modules. A node_modules folder can be on the same level as the current file, or higher up in the directory chain. Node will walk up the directory chain, looking through each node_modules until it finds the module you tried to load.

https://www.typescriptlang.org/docs/handbook/module-resolution.html

https://nodejs.org/api/modules.html#loading-from-node_modules-folders

samchon added a commit that referenced this issue Feb 20, 2023
Fix #251 - support yarn monorepo in setup wizard
@samchon
Copy link
Owner

samchon commented Feb 20, 2023

Update to the latest, then be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants