We recently regrouped several repositories into a single monorepo using turborepo for better code reusability using local packages.
Our folder structure looks like this:
/apps
| /app1
| /app2
/packages
| /package1
| | /some-folder
| | | someHelper.js
| | index.js // Main entry point exporting everything
package1 package.json file looks like this
{
"name": "package1",
"main": "index.js",
// Omitted irrelevant properties
}
Apps package.json look like this
{
"name": "app1",
"dependencies": {
"package1": "*"
}
// Omitted irrelevant properties
}
When in the context of an app and I reference someHelper
, the intellisense import suggestion gives the following:
import someHelper from "<rootDir>/packages/package1/some-folder/someHelper";
while I would like it to import like this:
import { someHelper } from "package1";
Both imports work, but the second one is cleaner. I just cannot make VSCode to work that way.
I tried different combinations of jsconfig.json path aliases at all levels (apps, packages and root directory) but none ever had the desired effect.
Anything I'm missing?
Have you tried adjusting VS Code's javascript.preferences.importModuleSpecifier
setting?
typescript.preferences.importModuleSpecifier
is also available for TypeScript projects.