-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Path mapping in yarn workspaces #21137
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
A path mapping can list multiple paths to try. Could you try this with: "protonbufjs": ["../node_modules/@types/protobufjs", "../../node_modules/@types/protonbufjs"] That way should work in both situations. |
Yes, I thought of that too, but this is only a stopgap solution given the fact that packages in yarn workspaces can be arbitrarily nested. |
Would it be possible to give Path mappings aren't supposed to go through module resolution -- since it's the exception to normal module resolution. It's an unusual situation to want different parts of your code to resolve the same package to two different locations in the same |
Mh, I see your point. Having an extra package just for the tests seems a bit overkill for me. I will see how I can work around it. Feel free to close this issue. |
OK. You could always just include as many |
I have a problem in which path mapping is not flexible enough for different project scenarios.
I have the following project layout: I have separate
main
andtests
directories which use different versions of theprotobufjs
type definitions.Project layout
The main sources should use the newer definitions that come included with the npm package, the tests use generated code that refers to an older and incompatible version of
protobufjs
that uses the definitions fromnode_module/@types
. I therefore use the following path mapping, which works as intended:/src/tsconfig.base.json
/src/main/tsconfig.base.json
/src/test/tsconfig.base.json
The problem arises when I include this package in a yarn workspace. In this situation the
node_modules
folder gets hoisted up one level, and since the path mappings are interpreted as being relative tobaseUrl
, they do no longer resolve to a valid directory.Quoting from the yarn documentation this seems an obvious problem:
I see two ways to resolve this problem:
Require paths to be interpreted as being relative to
baseUrl
to have a leading./
. Interpret path mappings without it as relative paths subject to node module resolution logic. This would require small fixes for many projects.Introduce a special leading signifier (e.g
^
) or add a special attribute incompilerOptions
(e.g.nodePaths
) for path mappings subject to node module resolution logic.The text was updated successfully, but these errors were encountered: