Description
@andrewbranch
Sure, here's a repo that has the issue.
This is based on a simplification of our own yarn monorepo. We've got a common
project that contains stuff that's shared between frontend and backend (the backend
project is omitted), and a web
project that references it via a @common
alias. Each project has its own tsconfig.json
. I believe this is pretty similar to the example repo posted above. To see the problem, hop into web/src/Helper.ts
and try to use a "Quick Fix" to import square
from the common
repo.
This example repo doesn't include any of this extra stuff because it suffices to show the issue, but for context, in our real repo web
is a CRA-based Webpack app. We run it via yarn tsc --build --watch & react-app-rewired start
(we run tsc
separate because CRA
's setup doesn't understand building projects). We want to import the compiled code in common/dist
via an alias (e.g. import { square } from '@common/MyModule'
).
Our biggest issue is the one mentioned in the comment above - VSCode auto-import suggests relative paths to the original .ts
file no matter what. There's a few issues here:
- it leads CRA to barf because of the attempt to import a file outside of the project (this works fine with aliases, with some monkey-grease)
- we want to be importing the compiled
.js
file, not the original.ts
file - Depending on VSCode settings, it won't even import the correct file.
What I mean by that last point is, if I try it with the "Import Module Specifier" preference set to "shortest", it works (although with a relative path, which is still undesirable):
But if I set "Import Module Specifier" to "non-relative", it curiously gives me:
Which is simply broken - an immediate compilation error.
It's totally possible - and would be great if! - this is just a configuration issue on our part and there's a different/better way to do it.
Thanks for your help!
Originally posted by @adamsmasher in #39778 (comment)