Menu "Show intention actions" does not suggest "root" import of scoped module/component (JavaScript)

Hi there ! First, thanks for you hard work trying to keep up with the fast-paced ecosystem JS/ES is :)

 

I just wanted to report an issue about import suggestions inside the "Intentions actions & quick-fixes" menu. 

I'm using Intellij 2018.1.2 (and the same applies to 2017.3 & Webstorm)

 

Case 1 - simple package :  I have a library named "my-lib" which uses ES modules inside an es folder, ie:

- my-lib / es / index.js (exporting some modules)

 

Case 2 - scoped package : I have the same lib but scoped ie. named "@myCompany/my-lib" which contains the same es folder, ie:

- @myCompany / my-lib / es / index.js (exporting same modules)

 

Let's say you install (via Yarn or NPM) these two dependencies.

When you try it to use one module exported in "my-lib/es/index.js" named "Button", then in the "intentions & quick fixes" menu you get the following suggestions:

Case 1: (simple package)

- import { Button } from 'my-lib/es/index';

- import {Button} from 'my-lib';

This is all good.

 

Case 2: (scoped package)

- import { Button } from '@myCompany/my-lib/es/index';

Not really good, the "root" import is missing, ie. I was expecting a suggestion : import { Button } from '@myCompany/my-lib';

 

I may have missed something but it seems, when using a scoped package, the import suggestions does not provided the more generic import , what I call the "root" import :).

Do you have any suggestion to tell Intellij/Webstorm to handle this a bit better? Maybe some config I'm missing?

 

Thanks in advance for any response,

 

Regards,

 

4 comments

>I may have missed something but it seems, when using a scoped package, the import suggestions does not provided the more generic import , what I call the "root" import :).

Import suggestions for scoped npm modules work just in the same was as others... To me, everything is imported properly when using such packages.

Please can you share a sample project we can use to recreate the issue? also, are there any symlinks in your project path?

0

Hi Elena, thanks for answering ! 

There is no symlinks in my project. 

I reproduced the issue with a simple project: https://github.com/thomasbertet/intellij-360000466210

Just clone the repo, run a yarn and hit the "Alt+Enter" on the "Button" element in index.jsx

This repo is the "consumer" repo, meaning it imports via its "package.json" two dependencies, one simple named "myLib" and one scoped named "@myCompany/anotherLib".

You can just also check the two "lib" repo that are imported: 

- The simple "myLib" https://github.com/thomasbertet/360000466210-simple

- The scoped "@myCompany/anotherLib" https://github.com/thomasbertet/360000466210-scoped

You will see the hierarchy and content of the index.js files are the same, but Intellij does not provide equal suggestions for both libs as you can see in the following screenshot :

There you can see, for the scoped package, Intellij does not suggest the "root" import. 

Please let me know if you need anything else to reproduce.

0

Please sign in to leave a comment.