Open IlyaSemenov opened 1 year ago
Of course this is arguably an edge case scenario, what I am really struggling with is that I can't add a new test dependency under tests/fixtures/tsconfig/node_modules/my-new-test-dependency
with its tsconfig.json
(for #96) - it ignores its tsconfig.json
altogether even if I run it directly (not as a dependency). I then narrowed the problem to having node_modules
in path.
I have this strange behavior:
project/node_modules/dependency
breaks tsx in dependencyproject/node_modules/<symlink to dependency>
doesn't break it, but, if the dependency is located within a node_modules
directory, then it breaks again.Doesn't sound related to the issue being reported here. Please file a separate issue.
No, it's the exact same issue. Any file that has node_modules
in its real path will ignore tsconfig, because esm-loader and cjs-loader will refuse to apply tsconfig.json to it.
Elaborating on how your code is breaking (what code? what error?) would add more value to this thread. Right now, it's hard for readers to understand the problem you're experiencing.
Does removing those two lines fix it for the reproduction provided?
If you feel strongly that it's the same issue, that's fine. But if this gets fixed and doesn't resolve your issue, you'll have to open a new issue. Always better to file earlier so it's on my radar & roadmap.
The difference in behavior when the parent path contains the string /node_modules/
definitely seems to be caused by those two lines, so solving this will solve my issue.
First, my usecase - I'm writing a website generator which is supposed to be installed with npm and run with npx, and to import files from the main package directory.
This now breaks my paths configuration if my generator package is properly installed (i.e. not symlinked), because the files that the start script loads are now within a node_modules
directory, so tsx refuses to use my tsconfig.json to resolve paths, even if I run the script or tsx itself manually from that directory.
My current development work around is mv node_modules mode_nodules; ln -s mode_nodules node_modules
. This "works", i.e. the start script runs tsx which correctly uses paths from the specified tsconfig to resolve modules.
The drawback is that all modules from all packages are now loaded using the same logic specified in the originally used tsconfig. This hasn't broken anything in my project so far, but it has made the load time a tiny bit longer. (Interestingly, it also gave me a warning which found a bug in jsonpath. I must report it after I get some sleep.)
I can see two ways of fixing this:
node_modules
directory.Any reason for publishing a non-compiled version to npm that needs a real-time bundler to run? That's very untypical. I believe in your case it makes sense to use e.g. tsup and publish cjs and mjs versions which will start natively.
The website generator imports jsx files which need to be transpiled before import, so using tsx at runtime is already a part of the project.
I realize that there must be a way to accomplish that without loading the whole thing through tsx every time it's started. But using tsx as a drop-in replacement for node would make it much more comfortable, and the expense is really just compiling several additional files at startup.
Edit: It's actually a web server, not really a website generator. It imports some jsx files at startup and can import new files during runtime, so compiling the whole site at startup is not an option.
I'm encountered the same issue. In the above screenshot, the two entry files have exactly the same content, but only the one outside node_modules
can be loaded with paths
support.
I haven't studied the source code carefully, but I want to ask what is this line for? Will modifying the logic here help solve this issue? (Actually I can't even find the relavant code in dist, so I have no idea how to test on it.)
Encountered the same issue now. Removing this line helped solve it:
I'd either remove it completely - I don't see it being a big performance bottleneck as the resolution is executed only once per import; or at least make it a flag when running tsx, something like --allow-tsconfig-paths-in-node_modules
.
@privatenumber your input would be grately appreciated here. If you're still struggling on understanding how this exactly happens, I'd be happy to create you a repro.
Bug description
I put my project inside
node_modules
directory (not even realnode_modules
alongside somepackage.json
, just a new directory named that).After doing so, resolving tsconfig paths stopped working.
I expect tsx to be agnostic to where the project is located (as long as it has its own
package.json
andtsconfig.json
), same as esbuild is.Reproduction
I repeated this on Stackblitz: https://stackblitz.com/edit/node-qjlxvn
This does not completely resemble the description above (it uses a 'real' node_modules directory) but the very same code can be used to repeat the problem on a completely empty node_modules.
Run:
Environment
Can you contribute a fix?