WebStorm won't automatically import NX monorepo modules

I'm building a monorepo app in TypeScript using NX.  WebStorm won't automatically import from my other NX modules (which are prefixed with @myproj).  I can press Option+Return and select “Add import from @myproj/common” from the contextual menu, however it is very frustrating to do this for every import.  Please let me know if there is a way to configure WebStorm to make this automatic.  Thanks!

0

It generally works right out of the box. Could you please assist us by narrowing down the issue to a minimal repository project and sharing it with us?

0

Sure… I created an NX monorepo with two libraries, mylib and mylib2.  The exported mylib2() function in mylib2 won't auto-import in mylib (and vice-versa).  This is similar to my current setup where I have a node backend library and a common library.

Here's how I created the project and libraries:

$ code npx create-nx-workspace@latest jetbrains-nx

 NX   Let's create a new workspace [https://nx.dev/getting-started/intro]

✔ Which stack do you want to use? · none
✔ Would you like to use Prettier for code formatting? · No
✔ Which CI provider would you like to use? · skip
✔ Would you like remote caching to make your build faster? · skip

 NX   Creating your v21.2.1 workspace.

✔ Installing dependencies with npm
✔ Successfully created the workspace: jetbrains-nx.

 NX   Welcome to the Nx community! 👋

🌟 Star Nx on GitHub: https://github.com/nrwl/nx
📢 Stay up to date on X: https://x.com/nxdevtools
💬 Discuss Nx on Discord: https://go.nx.dev/community
$ code cd jetbrains-nx
$ jetbrains-nx git:(main) npx nx g @nx/js:lib libs/mylib

 NX  Generating @nx/js:library

✔ Which bundler would you like to use to build the library? Choose 'none' to skip build setup. · none
✔ Which linter would you like to use? · none
✔ Which unit test runner would you like to use? · none
CREATE libs/mylib/tsconfig.lib.json
CREATE libs/mylib/tsconfig.json
UPDATE tsconfig.json
CREATE libs/mylib/src/index.ts
CREATE libs/mylib/src/lib/mylib.ts
CREATE libs/mylib/README.md
CREATE libs/mylib/package.json
UPDATE nx.json
UPDATE package.json

added 2 packages, and audited 322 packages in 583ms

42 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

up to date, audited 322 packages in 373ms

42 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

 NX   👀 View Details of @jetbrains-nx/mylib

Run "nx show project @jetbrains-nx/mylib" to view details about this project.

$ jetbrains-nx git:(main) ✗ npx nx g @nx/js:lib libs/mylib2

 NX  Generating @nx/js:library

✔ Which bundler would you like to use to build the library? Choose 'none' to skip build setup. · none
✔ Which linter would you like to use? · none
✔ Which unit test runner would you like to use? · none
CREATE libs/mylib2/tsconfig.lib.json
CREATE libs/mylib2/tsconfig.json
UPDATE tsconfig.json
CREATE libs/mylib2/src/index.ts
CREATE libs/mylib2/src/lib/mylib2.ts
CREATE libs/mylib2/README.md
CREATE libs/mylib2/package.json
UPDATE nx.json

added 1 package, and audited 324 packages in 413ms

42 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

 NX   👀 View Details of @jetbrains-nx/mylib2

Run "nx show project @jetbrains-nx/mylib2" to view details about this project.

In libs/mylib/src/lib/mylib.ts:

export function mylib(): string {
  const _ = mylib2(); // won't auto-import from '@jetbrains-nx/mylib2'
  return 'mylib';
}
0

Thank you for your help in providing all the details. We managed to reproduce the problem and have created a new ticket:: WEB-73859. Please vote for it to get notified of any progress,

0

请先登录再写评论。