-
Notifications
You must be signed in to change notification settings - Fork 12.8k
TypeScript 3 project references with a separate outDir #27572
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
Comments
outDir
This is actually unrelated to project references. When using Ultimately this is just about how TypeScript doesn't touch import paths at all, and you need to import from wherever the |
Also, see #16577. |
I think I'm a bit confused about the project reference feature that is added in TypeScript 3. If you look at my project structure, before using the project references, I had something like this:
And I could successfully run it by running What I didn't like about this was that everything was getting copied into A's output directory. I thought project references are here to fix this problem. So, my questions is that how is the project references features is supposed to be used in case like mine?
Thanks in advance for your answer. |
@DanielRosenwasser Also related to my previous comment, can you elaborate a bit more on the 'you need to import from wherever the |
I'm also really confuse about it, all the example i found are not working properly... |
Where could I found a working example of project reference feature? |
@DanielRosenwasser can you elaborate a bit more on the 'you need to import from wherever the .js and .d.ts files end up (rather than the input files)'? How should I change importing from the shared module when I have project references? |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Anyone would expect that when you reference a project, you also reference the output created by that project. Otherwise what you reference it for? This is completely missing the point of Keep It Simple, and make using this technology fun, not a nightmare. Really weird that this ticket is closed with no proper resolution. At least a link to a working solution should be explicitly pointed out. |
Combined with VSCode's automatic imports that link to source .ts file, this is a bad solution. For example, in my project I have this structure:
Root {
"references": [
{
"path": "./src/tsconfig.json"
},
{
"path": "./tests/tsconfig.json"
}
]
}
{
"extends": "../tsconfig-base.json",
"compilerOptions": {
"outDir": "../lib",
"rootDir": "."
}
}
{
"extends": "../tsconfig-base.json",
"compilerOptions": {
"outDir": "../tests-compiled",
"rootDir": "."
}
} If src/foo.ts exports type This makes VSCode inconvenient because after every automatic import I need to edit import to point to .js file (also make sure its compiled, so I can't edit two files at the same time). So one software has bug: TypeScript or VSCode. I prefer to think its TypeScript bug. edit: I was wrong. By adding this to root tsconfig.json VSCode starts linking files from lib, so now it all makes sense:
|
To clarify, if you're in Now the actual problem you might run into is that if you use relative paths to I think in this situation, your best bet is something like path-mapping or symbolic linking (maybe like in this Lerna example). |
I want to mention that this is still a big use ability issue almost 3 years later. Having the structure of your project be implicitly limited in a way that most programming languages allow without any guide or explicit explanation is anti-user design. Making the generated JS import location patched from the output location of the referenced project seems the most obvious solution at first glance. Or, at the very least, having an explicit warning about import locations if they are relative and not at the same nesting level with the reference projects output. |
I have wasted so much time on this (in friendly terms) half-baked and misleading feature now, and no success. The typescript compiler allows you to "compile" code that's impossible to run. What's the job of the compiler and static analysis then? This is a big mess. You have to manually mirror your source and target directory structures. It becomes practically impossible as soon as your |
TypeScript Version: 3.1.1
Search Terms: Project References
Code
I'm not sure if this issue is addressed somewhere else, at least I couldn't find an answer, so I'm asking again. I'm trying to use project references for a shared project with specified
outDir
.The directory structure looks like this after the compilation:
Contents of the
Shared
directory:shared.ts
tsconfig.json
Contents of the
A
directory:a.ts
tsconfig.json
Compile the files by running
tsc -p .
in theShared
andA
directories.Expected behavior:
The application run successfully when running
node dist/a.js
in theA
directory.Actual behavior:
Files compile successfully, but when running
node dist/a.js
in theA
directory, I get the following Error:The reason is that in the generated
a.js
file, the reference to the imported module is not resolved properly:Is there a way to get it working without putting all output files into the same directory?
The text was updated successfully, but these errors were encountered: