VSCode - Turborepo - Automatic import suggestion for local packages misses the main entry point

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?

2

1 Answer

Have you tried adjusting VS Code's javascript.preferences.importModuleSpecifier setting?

typescript.preferences.importModuleSpecifier is also available for TypeScript projects.

enter image description here

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like