-
-
Notifications
You must be signed in to change notification settings - Fork 534
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
ts-node with project references in a lerna monorepo #897
Comments
|
Thanks @blakeembrey
Thanks! |
Hi again, |
@kerdany Thanks! Interestingly I get the same error in development with VS Code and |
Another interesting part of this is that it's related to import { greet } from "@myproj/lib/src/index"; Edit: Don't expect this to work in the next major version though, I've been having a lot of trouble with getting project references working and this also fails with VS Code |
Have you done any progress or got any clues for this? I just ran into the same issue as well |
I also ran into this trying out packages in yarn workspaces. When wanting to debug with |
FYI it looks like they've added API support for building project references.
|
FYI: the obvious workaround is to set |
@krzkaczor, I tried setting this on the command line (using |
I ended up using
Here, the |
I'd also like to use ts-node with project references. Until this is supported, I'm using the following workaround: tsc-watch -b --onSuccess 'node dist/index.js' On my project, this picks up changes slightly faster than using |
Any progress on it? |
Line 921 in f77e1b1
This comment is confusing me. Does it mean to say that there is a Here is a ~hidden pending change to the typescript compiler API wiki: https://github.com/microsoft/TypeScript-wiki/pull/225/files#diff-709351cd55688fbcb7ec0fc9973ee746R407 I am trying to figure out adding project references support to ts-node and then ts-node-dev, but I have low confidence that I can figure it out as a beginner contribution. If any of the maintainers have explored this before, can they please share their findings so far? My basic guess is that we need a new CLI flag ( Lines 787 to 799 in f77e1b1
If it were that simple, it'd probably be done by now. I think that BTW, where is it that the compiled in-memory script is executed? I don't have any ideas of what to do after @sheetalkamat might know exactly what to do. |
I think we can get away with enabling this behavior by default, or at least enabling by default when
Here is where we hook into node's module loading mechanism: Lines 1022 to 1049 in f77e1b1
Node internally reads the file's contents from disk, then passes it to |
Isn't typescript's https://www.typescriptlang.org/docs/handbook/project-references.html#caveats-for-project-references says:
which I don't really understand - but why wouldn't ts-node need to respect this opt-in behavior? Has this been reattempted since the API was made public to the extent that it is currently, and with the knowledge of the documentation in the wiki PR? I didn't see any branches here for it. Just wondering what trees the community can avoid barking up. |
The following answers are based on memory. They might be wrong, they're not perfectly written, and they're long, but I tried to provide as much detail as possible.
Correct,
That's a good question. If the user runs a script in projectA which imports a file from projectB, what should we do? Should we follow project references and compile the file in projectB, using projectB's compiler options, essentially defaulting to Also, To get more detailed, TypeScript has the luxury of eagerly loading all projects and files, type-checking and emitting them all at once. It starts with a single
I use the term Possible simplificationsThis all needs research, but here are a few things that might simplify
About incremental and tsbuildinfoI believe that implementing project references with the performance benefits of
|
I realized I should clarify something:
What I mean by this is, if you import a file from projectB, then |
@JasonKleban I've been thinking about a good place for a beginner to start contributing to |
Bump |
I also have this problem and it would be really nice to avoid running the extra |
This is a bit of a hack but I've written a small script
Should do until |
This thread is really hard to find... Been on the hunt for hours on this issue. It's a really necessary feature |
Do you want to try your hand at writing a pull request for it? Check out #1514 and see if there's anything you want to help with. Alternatively, if your employer is willing to pay for the feature to be prioritized, we might be able to work something out. We've not done that sort of thing before but we could give it a try. |
https://gitlab.com/darren-open-source/mo-ts-scaffold If it helps at all, I setup a basic TS project with modular entrypoints... I've created a list of objectives (Which were based on many TS complaints across multiple forums/tickets) and have basically resolved most of them besides this issue. Happy for anyone to check it out and try get things working. Hoping to create a good minimum viable TS (For node) project so developers have a great starting point. I've found that, unfortunately, for any decent project there needs to be a build pipeline. I didn't go towards babel, as I prefer webpack to just put everything into one bundle file... This also solves a lot of potential deployment and production reference issues. |
I've just stumbled upon this very same issue. I couldn't find any info on the best possible way to work with |
+1 I would also love a way of running ts-node on a cli that lives in a monorepo (and imports from other monorepo packages using tsconfig references) |
Essential for developing monorepo cli apps. +1. |
thanks @zomars !!! I was having issues with a custom typing and the This is my tsconfig.json of the test folder that references the source and has to reference a custom typing the source uses:
|
Improvements: - The common/ project is automatically built by dependent projects - Building common/ in in the "prepare" script is thus no longer necessary - Vite and server hot-reloading now work if files in common/ change - Recompiling common after every change is done automatically - Using "go to definition" now jumps to the .ts file rather than the .d.ts Changes: - Use TypeScript project references to refer to common/ from client/ and server/ - Set "composite" and "declarationMap" options in common/tsconfig.json - See https://www.typescriptlang.org/docs/handbook/project-references.html - Use tsc --build in order to build references automatically - Replace nodemon and ts-node with ts-watch in server in order to use the new tsc --build mode - See TypeStrong/ts-node#897 (comment) - Remove now unneeded SIGUSR2 signal handler which was for nodemon - Use tsc-watch before Vite in client in order for hot-reloading to work if common/ changes - Update TypeScript version - Add vite.config.node.json to be consistent with expected Vite project defaults GitLab: #151 Change-Id: Id2f84fe45e44c4d8b4e6d3b324e1aee322c52df6
Improvements: - The common/ project is automatically built by dependent projects - Buildling common/ in in the "prepare" script is thus no longer necessary - Vite and server hot-reloading now work if files in common/ change - Recompiling common after every change is done automatically - Using "go to definition" now jumps to the .ts file rather than the .d.ts Changes: - Use TypeScript project references to refer to common/ from client/ and server/ - Set "composite" and "declarationMap" options in common/tsconfig.json - See https://www.typescriptlang.org/docs/handbook/project-references.html - Use tsc --build in order to build references automatically - Replace nodemon and ts-node with ts-watch in server in order to use the new tsc --build mode - See TypeStrong/ts-node#897 (comment) - Remove now unneeded SIGUSR2 signal handler which was for nodemon - Use tsc-watch before Vite in client in order for hot-reloading to work if common/ changes - Update TypeScript version to fix issue - Add vite.config.node.json to be consistent with expected Vite project defaults Future work: - Updating to the latest TypeScript version was needed in order for this to work. However, ESLint complains that the TypeScript version is too recent. An update for ESLint's TypeScript parser should be applied as soon as it is released. GitLab: #151 Change-Id: Id2f84fe45e44c4d8b4e6d3b324e1aee322c52df6
Improvements: - The common/ project is automatically built by dependent projects - Building common/ in in the "prepare" script is thus no longer necessary - Vite and server hot-reloading now work if files in common/ change - Recompiling common after every change is done automatically - Using "go to definition" now jumps to the .ts file rather than the .d.ts Changes: - Use TypeScript project references to refer to common/ from client/ and server/ - Set "composite" and "declarationMap" options in common/tsconfig.json - See https://www.typescriptlang.org/docs/handbook/project-references.html - Use tsc --build in order to build references automatically - Replace nodemon and ts-node with ts-watch in server in order to use the new tsc --build mode - See TypeStrong/ts-node#897 (comment) - Remove now unneeded SIGUSR2 signal handler which was for nodemon - Use tsc-watch before Vite in client in order for hot-reloading to work if common/ changes - Update TypeScript version - Add vite.config.node.json to be consistent with expected Vite project defaults GitLab: #151 Change-Id: Id2f84fe45e44c4d8b4e6d3b324e1aee322c52df6
Hello, I was searching for a solution for like 2 weeks, and I think I found a perfect workaround. the whole idea is that I run my main app using nodemon and ts-node, and except watching my app folder, i added another folder to watch but not the src folder of my library but the build (output folder) and extended the watch to .js files as well. Then, run tsc -b -w on my library which watches the library itself, and rebuild if necessary, and if it emits new .js files, nodemon catches it as well. and it is even in the right order |
so assuming you have like 3 different libs and 1 app in your monorepo... do you start basically 4 processes each time you start coding (3 also this workaround means that each change in the lib would be propagated within 2 rebuilds (1 of the lib itself and 1 of the app that is using the lib), but the changes in the app would be propagated within 1 rebuild, which means inconsistency of the time interval between saving changes and ability to run the code... it indeed does the job but not without tradeoffs |
Ran into this issue today as well, although I'm just using yarn workspaces rather than lerna. Maybe worth changing the issue title since this is a broader problem? I've reproduced with a minimal setup here if it helps anyone: https://github.com/daniel-savu/ts-node-bug |
I have an npm workspaces and have same issue |
Anybody have any insight into this as of March 2024? Is this supported yet? Thanks! |
I ended up avoiding ts-node and other typesctipt runners. Here is an example repo for how achieve live-reload and so on solely with |
https://www.npmjs.com/package/tsc-watch can be used as well for tsc driven workflows |
I'm using
lerna
with typescript project references for a node application containing two packages. Packagelib
and packageapp
(which depends onlib
).I've configured typescript project references so that package
lib
is built automatically whenever we runtsc --build
inside packageapp
(i.e. to build for production).Here's how the
tsconfig.json
files are configured for each of the packages:packages/
lib
/tsconfig.json:packages/
app
/tsconfig.json:Currently, running
tsc --build
(insideapp
) compiles typescript to javascript in thedist
directory in each ofapp
andlib
perfectly fine, the setup runs flawlessly in production mode.The problem, however, is that trying to run the project in development with
ts-node
vianodemon --exec 'ts-node src/index.ts'
in development fires the following error:What seems to be happening, is that
ts-node
is looking for the@myproj/lib
package insidenode_modules
directory (symlinked bylerna
), instead of compiling it on the fly through typetcript's project references, as is setup inside bothtsconfig.json
files.I validated my theory by:
tsc --build
first (which also builds thelib/dist
code).nodemon --exec 'ts-node src/index.ts'
again, and it ran fine then.Which means that
ts-node
in this case is loadinglib
via the compiled.js
code insidelib/dist
(symlinked bylerna
), NOT via compiling its.ts
code on the fly (via references).I'm using
ts-node@8.4.1
(currently the latest version).Some questions:
Doesn't
ts-node
currently support project-references yet or passing the--build
flag totsc
yet?Am I doing something wrong in my (e.g.
tsconfig.json
) configurations that's causingts-node
not to compile/buildlib
.I can see that a new
--build
flag is being added tots-node
in themaster
branch (commit), but it seems that it's irrelevant totsc
's--build
flag.Note: Currently I'm working around this (without ts-node) via
nodemon --exec 'tsc --build && node dist/index.js'
till I get this figured out.Thanks!
The text was updated successfully, but these errors were encountered: