moduleResolution: "Bundler"

When using moduleResolution “Bundler” in a typescript project, I'm getting these errors on imports:

TS2792: Cannot find module lucide-react. Did you mean to set the moduleResolution option to node, or to add aliases to the paths option?

When switching over to “Node”, all imports resolve fine (lucide is part of node_modules in the root of my monorepo). Is this an error with my configuration perhaps, or something that WebStorm didn't fully implement yet?

1
5 comments

Can you please share a bit more context around the problem? What does your tsconfig.json look like?Which version of Typescript are you using? Please share a screenshot of the Settings | Languages & Frameworks | TypeScript page.

 

0

Thanks for the response. Investigated a bit more and it seems that typescript in the root of the monorepo has to be set to at least 5.0 if a child-package in the monorepo makes use of moduleResolution: “bundler”.

In my case, the root had typescript 4.x and the root/packageA had typescript 5.x. When upgrading the root to 5.x, the errors instantly went away.

I wonder if that's intended though? E.g. a sub-package in a monorepo can theoretically have a different typescript version, but intellij uses just the roots.

0

The package installed in the root is used by default, but you can choose a different version in Settings | Languages & Frameworks | TypeScript.

Having multiple Typescript versions in a single project is not currently supported. We’ve discussed supporting this before but don’t think it’s worth the engineering effort to support. It would require running multiple typescript servers (which are expensive in terms of memory and CPU usage). It's better to use a single window with a single tsserver across all folders in your workspace as compatibility problems between TS versions are actually not very common (although certainly not impossible to hit).

1

Elena Pogorelova Maybe mentioning this in the error message should help. This issue and its message is confusing, especially for novices.

0

Brice the error comes from the Typescript compiler, we can hardly do anything to make it more verbose.

0

Please sign in to leave a comment.