nestjs example with node-package requires includes/paths that point to local node_modules
- If you add
@company/browser-packageto the nestjs app and runmoon run nestjs-app:devthen:
- the tsconfig updates with a new reference that point to
../../packages/browser-package
- If you hard revert all changes and try again with
@company/node-package, nothing happens. - If you manually do the changes to mimic what was done in
#1and then try to createsome.service.tsthat makes use of theaddfunction from@company/node-packagethen you get an error that this file(or any file in the nest-js package) is not included. This is because theincludesdirective is not in the nestjs-app tsconfig.json but instead in thetsconfig.build.jsonwhere the editor can't see it. - if you make that correction for
#3then you get the next error which is that thenode-packagefiles are not in the rootDirexamples/apps/nestjs-app. addingrootDir: "./"to the roottsconfig.options.jsonfixes this.
- if you're following along incrementally here, then
moon run nestjs-app:devwill work - remove the
builddirectory now
- now that we have
rootDirin the roottsconfig.options.jsonand our node-package properly referenced in the nestjs-app tsconfigs... runningmoon run nestjs-app:devfails because thebuilddirectory no longer reflects the structure of the nestjs-app src directory, instead it reflect the structure of the monorepo so nest-cli can't findbuild/src/main(which is now atbuild/apps/nestjs-app/src/main) - if you roll all the changes back to
#2and instead of using../../packages/node-package, usenode_modules/company/node-packageand now everything works.
ugh... looks like a lot of these issues might be caused by:
- improper typescript selection in the editor (it defaults to the ide instance of typescript instead of the one in node_modules)
- which was further compounded by not hard resetting the repo between certain steps so that the moon cache knew it had to make the right changes to the various tsconfigs
I'm sure there are many issues with this repo, since it's not actively maintained, and more just a proof of concept of how things are organized. The nest app was also contributed to a third-party, so probably wasn't tested very much.
With that said, configuring TS is always such a giant pain.
yeah i revisted my steps and at step 2 after removing moon cache and nestjs build dir, everything works.
perhaps there's some anecdotal evidence here for more nuanced cache busting?
- in a users project config (somehow?), or
- in moon core logic when determining how/if/when it should modify tsconfigs?
Nope, this is still an issue. I've uploaded an example
Main issue is this https://github.com/airtonix/moon-examples/pull/1/files#r2034166204
Ok some discovery in https://github.com/airtonix/moon-examples/pull/1
If a moon repo has a nestjs app that never uses anything from the rest of the monorepo, then it can be structured just like it currently is in the moon example repo. (as what nest-cli calls a "single app repo")
However, in a monorepo that's very unlikely to remain the case.
So in the case where we start using other parts of the monorepo, two things have to change:
- the
nest-cli.jsonneeds to move to the root of the monorepo. - the
nest-cli.jsonnow needs to nest the original contents of the apps nest-cli.json within aprojectskey.
At this point i can run (from the root of the monorepo mind you):
nest start nestjs-app
and it builds and runs.
What I can't seem to do (which I'll probably need to do more research in to moon) is this:
moon nestjs-app:dev
my theory is that Moon is incapable of running tasks for a project from the root of the repo?
edit... I was able to overcome it with the jankiest of jank...
dev:
command: bash -c "cd ../.. && nest start nestjs-app --watch"
https://github.com/airtonix/moon-examples/pull/1/commits/f6444dc556f9c3e13931b4ded9074d98c534ea96
@airtonix Would this option work? https://moonrepo.dev/docs/config/project#runfromworkspaceroot
Also this seems like a limitation of nest js if it can't run in a monorepo?
Yep, that also works.
Perhaps for now we add a second nestjs example? one that imports and uses node-package and has a nest-cli.json at the root of the repo?
and also update the nestjs guide to mention these aspects about nestjs
The nestjs in this repo is probably out of date. I wonder if this is still an issue with a newer versoin.
Yeah nothing about the newer verson of nestjs has changed with regards to this problem.
I think the way NX.dev solve this is by providing a webpack bundler that obviates the need to leave the project directory or deal with the fact that such a tsconfig setup would result in the build output directory reflecting the resolved tree caused by rootDir.
In fact I could imagine this would not be an issue unique to nestjs, any other framework that relies on tsc to build the app before it runs would have some variant of this challenge
My original solution to this problem was to rely on the fact that my package manager created a node_modules directory inside the nestjs-app directory.
This meant i could:
- avoid the need for
rootDirin the root tsconfig - not have my
apps/nestjs-app/builddir reflect the monorepo structure. so i can now just runnestin the project directory
BUT... to get here requires another kind of jank:
- my nestjs-app tsconfig needed to point references, paths and includes to
node_modules/@company/nodejs-pacakageinstead of../../packages/nodejs-package
ok so just tried another way to solve this problem.
and it works?
https://github.com/moonrepo/examples/commit/5baacaa6a976d6bbd98e0277c9780cbadd0611d2#diff-1b7017c24b9d5587ec007d51cab6350ad0725b3bd0f45a957f635bb79a0164dbR4-R6