nx icon indicating copy to clipboard operation
nx copied to clipboard

WebStorm always chooses the wrong auto import path in a workspace

Open mbriggs opened this issue 9 years ago • 8 comments

Loving nx <3

This is probably not in your control at all, but any time WebStorm auto-imports something, it chooses the @project-name/lib absolute format, even with the symbol you are importing is in the same directory of the file you are currently working on. Ideally that format would only be used if you are in a different lib / app.

This is sort of at the "annoyance" level, but its the worst one for me after a few days of using workspaces, so figured I would report.

seeing this on

WebStorm 2017.2.5 Build #WS-172.4343.25, built on October 20, 2017 JRE: 1.8.0_152-release-915-b12 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Mac OS X 10.12.6

mbriggs avatar Nov 02 '17 14:11 mbriggs

I noticed that this stopped working with the new patch of 2017.2.5. I wonder if it's just a setting in the typescript of webstorm.

matthewharwood avatar Nov 08 '17 23:11 matthewharwood

@mbriggs I agree, that drives me nuts too. :) But I don't think there is anything we can do on the Nx side of things in the tsconfig file to help WebStorm be aware of those scenarios. We have several WebStorm users though, so if a solution arises in the future I am sure we will work it in!

jschwarty avatar Nov 14 '17 23:11 jschwarty

Go to Settings/Preferences dialog (⌘,) -> Code Style -> Editor -> choose JavaScript or TypeScript -> imports tab -> select only in files outside specified paths Screen Shot 2019-05-13 at 10 51 18

brampeirs avatar May 13 '19 08:05 brampeirs

... does this option exist for vscode too? only found Typescript->Prefs->Import Module Specifier but this does not allow me to set an equivalent option 🤔

skydever avatar Jun 05 '19 22:06 skydever

... does this option exist for vscode too? only found Typescript->Prefs->Import Module Specifier but this does not allow me to set an equivalent option 🤔

@skydever Did you have any luck figuring out this? I'm facing an issue with nx and next: when I use VS Code auto-import from the next app, it will use an absolute import which immediately triggers the @nrwl/nx/enforce-module-boundaries eslint rule. For example, with folder structure:

pages/
  entity/
    new/
      index.tsx
components/
  Loading.tsx

The generated import will be:

// in pages/entity/new/index.tsx
import Loading from 'apps/panel/components/Loading'

The possible settings are to always use relative paths, but that will prevent me from importing libraries in the proper way :(

martinsantibanez avatar Jan 19 '21 01:01 martinsantibanez

... sadly not, I use the lightbulb to import, it usually has the correct option available :/

skydever avatar Jan 19 '21 20:01 skydever

In case someone wants to set the setting described by @brampeirs in the .editorconfig-file, you need to use the following:

[*.ts]
ij_typescript_use_path_mapping = different_paths

borgiman avatar Jul 30 '21 10:07 borgiman

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

github-actions[bot] avatar Mar 23 '23 18:03 github-actions[bot]