Importing from webpack aliases does not work automatically

I have a javascript/typescript project with webpack. I'm using webpack aliases like this:
 

resolve: {
    alias: {
      "@config": path.join(ROOT_DIR, "/config"),
      "@hooks": path.join(ROOT_DIR, "/src/hooks"),
      "@icons": path.join(ROOT_DIR, "/src/assets/icons"),
      "@logos": path.join(ROOT_DIR, "/src/assets/logos"),
      "@images": path.join(ROOT_DIR, "/src/assets/images"),
      "@components": path.join(ROOT_DIR, "/src/components"),
      "@providers": path.join(ROOT_DIR, "/src/providers"),
      "@redux": path.join(ROOT_DIR, "/src/redux"),
      "@actions": path.join(ROOT_DIR, "/src/redux/actions"),
      "@reducers": path.join(ROOT_DIR, "/src/redux/reducers"),
      "@dispatchers": path.join(ROOT_DIR, "/src/redux/dispatchers"),
      "@selectors": path.join(ROOT_DIR, "/src/redux/selectors"),
      "@routes": path.join(ROOT_DIR, "/src/routes"),
      "@styles": path.join(ROOT_DIR, "/src/styles"),
      "@sizes": path.join(ROOT_DIR, "/src/styles/sizes"),
      "@theme": path.join(ROOT_DIR, "/src/styles/theme"),
      "@types": path.join(ROOT_DIR, "/src/types"),
      "@utils": path.join(ROOT_DIR, "/src/utils"),
      "@hoc": path.join(ROOT_DIR, "/src/hoc"),
      "@views": path.join(ROOT_DIR, "/src/views"),
    },


Webstorm recognizes them, since when I add an import, it does not show an error, and command + clicking on the imports take me to the file.

However, when I'm trying to use one function from this files, and the file is not yet imported, the autocomplete shows me the function, but selecting it won't add the import to the file.

 

As you can see on the image, numberUtils, which is inside of @utils, appears there, however selecting it, won't import it automatically. Is there something I can do?

0
8 comments

The issue doesn't look related to webpack aliases, it looks like a problem with auto import.

Once you choose this function from completion, can you use Alt+Enter to import the module? What is a result of choosing Show Context Actions from the function right-click menu?

0

Pressing Alt+Enter, shows me the option to import it:

And clicking on `Add import` works fine. Is there a way to make this happen automatically?

0
In screenshots I can see quick fixes from the Typescript Language service, but no quick fixes from the IDE. This likely means that the function is resolved to some global definition, so that the IDE doesn't offer an import quick fix. Once you choose a function from completion, before importing it, try   Ctrl+clicking it - what definition does it jump to?
0

If I don't add the import, it does not jump anywhere:

0
Could you share a sample project that reproduces the issue?
0

here it is, as simple as I could make it: https://github.com/pfeldman/webstorm-test

under `src` you'll find the utils folder, where numberUtils lives.

Try to import it on the App.js under `src` (Or any other file)

0

I have posted the link above but appears as pending approval

0

Thank you for your help in providing all the details. We managed to reproduce the problem and have created a new ticket: https://youtrack.jetbrains.com/issue/WEB-64464/Path-aliases-with-wildcards-in-name-break-module-resolution. Please vote for it to get notified on any progress.

0

Please sign in to leave a comment.