Doesn't work with project reference when same path is configured to difference packages.
See original GitHub issueLet’s say there is a directory tree like this.
packages
└── foo
│ ├── src
│ │ ├── hello.ts
│ │ └── index.ts
│ └── tsconfig.json
└── bar
├── src
│ ├── hi.ts
│ └── index.ts
└── tsconfig.json
And each file is like these.
// packages/foo/src/index.ts
import { hello } from '~/hello' // intended to import './hello'
export const helloworld = () => {
hello('world')
}
// packages/foo/tsconfig.json
{
"compilerOptions": {
"paths": {
"~/*": ["src/*"],
}
}
}
// packages/bar/src/index.ts
import { helloworld } from '@monorepo/foo'
import { hi } from '~/hi' // Same as importing './hi'
hi('there')
helloworld()
// packages/bar/tsconfig.json
{
"compilerOptions": {
"paths": {
"~/*": ["src/*"],
"@monorepo/*": [ "../*/src/" ]
}
},
"references": [
{ "path": "../foo/tsconfig.json", "prepend": false }
]
}
There are two different packages foo
and bar
in monorepo. They use the same path ~
internally.
Each package is developed by different teams independently. Thus, the consumer(bar
) doesn’t know whether the dependency(foo
) configures ~
as its path (And it shouldn’t care as well!).
So a developer of bar
runs npx ts-node -r tsconfig-paths/register src/index.ts
in packages/bar.
But it fails with the error message like this.
⨯ Unable to compile TypeScript:
../foo/src/index.ts:4:23 - error TS2307: Cannot find module '~/hello' or its corresponding type declarations.
4 import { hello } from '~/hello'
~~~~~~~~~
This happens because two packages use the same path internally. I expected tsconfig-paths fully respects typescript project reference feature, but it seems not.
How do you think this can be resolved?
Thanks.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:12
- Comments:5
Top Results From Across the Web
Project Reference & Nuget Package Reference Conflict - Key ...
First, try to remove the Project Reference of Project A in Porject B ,then Install Package in Project B and then add the...
Read more >Migrating from packages.config to PackageReference formats
In Solution Explorer, right-click on the References node or the packages.config file and select Migrate packages.config to PackageReference....
Read more >Reference assembly HintPath may become incorrect ... - GitHub
Hi. There is an issue with the approach how MSbuild discovers and handles referenced assemblies from Nuget and HintPath tag.
Read more >[NOTFIXED] Reference hint paths are broken for anyone who ...
I then add a package to a project, and it compiles and is all working for me so I checkin. "Dave" has disk...
Read more >Referencing a Local Private NuGet Package in your Solution
And here's the local folder setup: While this is not as easy as a relative path package reference as per my original musing,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m having the same problem, I’m currently using tsc-alias as an alternative.
Any updates on fixing this?