Auto-import unavailable for transitive dependencies not declared in package.json
Problem
Auto-import functionality does not suggest imports for dependency libraries that are listed only in a nested workspace package, not in the root package.json, when using npm workspaces in a monorepo setup. For example, if a package such as react is specified as a dependency only in a nested shared version package and not in the root package.json, code under [root]/src does not receive auto-import suggestions for react in the IDE.
Cause
Package management tools like npm may hoist dependencies, making libraries physically available in node_modules even if they are not declared in the root package.json. However, the auto-import mechanism does not treat hoisted or transitive dependencies as valid for new imports. IDEs rely on explicit dependency declarations in the importing package’s package.json and do not infer availability from hoisting or from dependencies of dependencies. This is to avoid exposing internals or accidentally resolving symbols from libraries not properly declared in the current context.
Resolution
Declare all dependencies directly in the package.json of any workspace package that imports them. With this setup, auto-import suggestions and symbol resolution work reliably regardless of npm layout, hoisting differences, or package manager specifics.
Please sign in to leave a comment.