3

There is a project split into several repositories cloned into separated folders. There is a library which is not referenced in package.json (and mustn't be) of other repositories as it is added via a build script.

How can I override WebStorm so that it does not display "Module is not installed" error for every import from that?

N.b., I need the library where it is, not in node_modules, so adding it to package.json is not a solution.

jaboja
  • 2,178
  • 1
  • 21
  • 35

6 Answers6

8

For me, this warning was displaying for all local imports. I resolved it by adding the path to the WebPack config file.

Preferences -> Languages & Frameworks -> JavaScript -> WebPack

akauppi
  • 17,018
  • 15
  • 95
  • 120
2

Other than File -> Invalidate Caches / Restart, which will take some time for WS to reindex, you can use this workaround

Savo Pejović
  • 133
  • 1
  • 9
1

You can disable the "Missing module dependency" inspection in the whole project either in Preferences | Editor | Inspections or by hitting Alt-Enter on the highlighted error, then arrow right - Disable inspection.

You can also create a new Scope that excludes that folder in Preferences | Appearance and Behavior | Scopes and then set the inspection's scope to it.

Ekaterina Prigara
  • 4,697
  • 3
  • 21
  • 17
  • 1
    What I'm trying to do is not to just get rid of the message, which is quite simple, but to be able to find code definitions in development repo via CTRL+B. Now I'm using a symlink in node_modules as a workaround but it would be better if there were an option to override the path without such hacks. – jaboja Jul 19 '16 at 10:12
  • In fact I would like to override paths for even more modules as WebStorm by default finds the definitions in transpiler output directory (which is "main" in package.json) and not the human-readable original sources. – jaboja Jul 19 '16 at 10:20
  • If you're using, for example, System.js for configuring the mappings, then it's supported in WebStorm 2016.2, but there're no internal configs that would allow you to map folders like that. If you'd like, you can report a feature request on the WebStorm tracker, but please provide a bit more details on your project structure and configuration: https://youtrack.jetbrains.com/issues/WEB – Ekaterina Prigara Jul 20 '16 at 11:31
  • It's also recommended to mark any folders with the generated output code as excluded from the project for better performance and resolve. Right-click on the folder in the Project view and select Mark as Excluded. – Ekaterina Prigara Jul 20 '16 at 11:33
  • Is it possible to do this with a `// noinspection` comment? If so, what's the name/ID to use? I tried `// noinspection JSMissingModuleDependency`, but it did not seem to work. – jacobq May 18 '22 at 21:02
  • Nevermind; list is here: https://gist.github.com/discordier/ed4b9cba14652e7212f5 (and I found the one I wanted, which was `NpmUsedModulesInstalled`) – jacobq May 18 '22 at 21:19
1

I solved this problem a bit differently. I added file webpack.alias-config.js in my main folder of project:

const path = require('path')

module.exports = {
    resolve: {
        alias: {
            '@': path.join(__dirname, 'src'),
        },
    },
}

Next I added path to this file (webpack.alias-config.js) in: Settings -> Languages & Frameworks -> JavaScript -> Webpack:

enter image description here

And now I can use this alias e.g:

import MyFile from '@/components/MyFile'
michal
  • 1,534
  • 5
  • 28
  • 62
0

In my case everything was set up correctly, but I had node_modules as exception in Settings: Editor -> File Types -> Ignore files and folders. The problem was solved after I removed it from there and waited for indexing.

mcmimik
  • 1,389
  • 15
  • 32
-1

For Laravel Mix users, Jetbrains products dont support the Laravel Mix config file. Use one of these workarounds:

beeftony
  • 145
  • 5
  • 16