question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Doesn't work with project reference when same path is configured to difference packages.

See original GitHub issue

Let’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:open
  • Created 3 years ago
  • Reactions:12
  • Comments:5

github_iconTop GitHub Comments

1reaction
xcfoxcommented, Jul 23, 2021

I’m having the same problem, I’m currently using tsc-alias as an alternative.

0reactions
thefakequakecommented, Aug 3, 2022

Any updates on fixing this?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found