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

Strange build of a monorepo projects. #533

Closed
fenixphp opened this issue Jan 16, 2020 · 9 comments
Closed

Strange build of a monorepo projects. #533

fenixphp opened this issue Jan 16, 2020 · 9 comments

Comments

@fenixphp
Copy link

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

If I run the "nest build" and "nest build cli"

+---dist
¦   L---apps
¦       +---cli
¦       ¦   ¦   tsconfig.app.tsbuildinfo
¦       ¦   +---apps
¦       ¦   ¦   L---cli
¦       ¦   ¦       L---src
¦       ¦   ¦       	main.js     
¦       ¦   L---libs
¦       ¦       L---database
¦       ¦           L---src
¦       ¦           	index.js
¦       ¦                   
¦       L---worker
¦           ¦   tsconfig.app.tsbuildinfo
¦           +---apps
¦           ¦   L---worker
¦           ¦       L---src
¦           ¦       	main.js        
¦           L---libs
¦               L---database
¦                   L---src
¦                   	index.js

Expected behavior

Expected something similar to this:

+--dist
|    +--apps
|        +--cli
|            main.js
|        +--worker
|            main.js
|    +--libs
|        +--database
|            index.js

Minimal reproduction of the problem with instructions

The project structure was generated by "nest-cli" 2 applications and 3 libraries.
1 library (database) was connected to both applications.

+---apps
¦   +---cli
¦   ¦   ¦   tsconfig.app.json
¦   ¦   ¦   tslint.json
¦   ¦   ¦   
¦   ¦   +---src
¦   ¦   ¦       app.module.ts
¦   ¦   ¦       app.service.ts
¦   ¦   ¦       main.ts
¦   ¦   ¦       
¦   ¦   L---test
¦   ¦           app.e2e-spec.ts
¦   ¦           jest-e2e.json
¦   ¦           
¦   L---worker
¦       ¦   tsconfig.app.json
¦       ¦   tslint.json
¦       ¦   
¦       +---src
¦       ¦       app.module.ts
¦       ¦       app.service.ts
¦       ¦       main.ts
¦       ¦       
¦       L---test
¦               app.e2e-spec.ts
¦               jest-e2e.json
+---libs
¦   +---account
¦   ¦   ¦   tsconfig.lib.json
¦   ¦   ¦   tslint.json
¦   ¦   ¦   
¦   ¦   L---src
¦   ¦           account.module.ts
¦   ¦           account.service.spec.ts
¦   ¦           account.service.ts
¦   ¦           index.ts
¦   ¦           
¦   +---console
¦   ¦   ¦   tsconfig.lib.json
¦   ¦   ¦   tslint.json
¦   ¦   ¦   
¦   ¦   L---src
¦   ¦           console.module.ts
¦   ¦           console.service.spec.ts
¦   ¦           console.service.ts
¦   ¦           index.ts
¦   ¦           
¦   L---database
¦       ¦   tsconfig.lib.json
¦       ¦   tslint.json
¦       ¦   
¦       L---src
¦               database.module.ts
¦               database.service.spec.ts
¦               database.service.ts
¦               index.ts
¦   .gitignore
¦   nest-cli.json
¦   package-lock.json
¦   package.json
¦   README.md
¦   tsconfig.build.json
¦   tsconfig.json
¦   tslint.json

Environment

[System Information]
OS Version     : Windows 10
NodeJS Version : v12.14.0
NPM Version    : 6.13.4

[Nest CLI]
Nest CLI Version : 6.14.0

[Nest Platform Information]
platform-socket.io version : 6.10.14
platform-express version   : 6.10.14
serve-static version       : 1.0.2
websockets version         : 6.10.14
mongoose version           : 6.2.1
passport version           : 6.1.1
swagger version            : 4.1.12
common version             : 6.10.14
config version             : 0.0.9
bull version               : 0.0.1-beta.4
core version               : 6.10.14
@kamilmysliwiec
Copy link
Member

Please, provide a minimal repository which reproduces your issue.

@fenixphp
Copy link
Author

@kamilmysliwiec
Copy link
Member

I see that you disabled webpack in the nest-cli.json. In the monorepo mode, if you want to bundle your libs with apps and produce a single executable file (for each app), you should use webpack.

@fenixphp
Copy link
Author

I do not need one file. I would like to do what the "tsc" compiler, only with exact paths for libraries.

@kamilmysliwiec
Copy link
Member

I would like to do what the "tsc" compiler, only with exact paths for libraries.

What's the reason?

@fenixphp
Copy link
Author

more convenient debugging and to use "instanceof" between applications relative to the library, it should be imported from one place.

@kamilmysliwiec
Copy link
Member

more convenient debugging

You can still use tsc in the development mode, but eventually, you should switch to webpack (to produce an app bundle).

to use "instanceof" between applications relative to the library, it should be imported from one place

If you plan to publish any of these libraries as, for instance, NPM package, you shouldn't use Nest CLI monorepo but rather lerna or yarn workspaces.

@fenixphp
Copy link
Author

Thanks for your reply.

He conducted a small experiment and posted it in the repository "https://github.com/fenixphp/nest-cli-issues-533".
Created 4 possible versions of the project which offers to generate "nest-cli" everywhere the webpack was disabled.
As a result, only the "04-monorepo-apps-libs" schema has the most unexpected result.
I still could not understand why there is a recursion (dist/apps/my-app/apps/my-app/src /) during assembly?

If we consider the situation in which we have 10 microservices and 10 libraries, then in the end we will get 100 copies of these same libraries.
Not sure if this is normal.

I believe that this is incorrect work of the build, but this is just my opinion.
But it's up to you, thanks.

@kamilmysliwiec
Copy link
Member

This is expected behavior of the current configuration in which tsc has to separately analyze all libraries that the app depends on and compile them along with the app (hence, somewhat hard to understand nested directories structure in the dist folder). Please note, we are not using project references feature #392. For monorepo approach, webpack should be used (and that's why webpack is automatically set to true).

If we consider the situation in which we have 10 microservices and 10 libraries, then in the end we will get 100 copies of these same libraries.

As I said, that's why you should use webpack. If you are willing to publish these libraries to NPM and access them independently from various repositories (e.g. when you have several micro services in different repositories), you should use either lerna or yarn workspaces instead of Nest CLI monorepo. The philosophy behind Nest CLI monorepo is different (it assumes that all shared libraries will exist in one repository, won't be published to any registry, and will be bundled together with the app).

@nestjs nestjs locked as resolved and limited conversation to collaborators Jan 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants