node_modules directory location
IntelliJ assumes the node_modules directory is at the root of the current module but this is simply not always the case, and I have to create all sorts of symlinks and junctions to cheat IntelliJ to find the node_modules or it wouldn't give me autocompletion.
My node_modules dir is inside my build directory, not outside. Is there a way to tell IntelliJ that my node_modules dir is elsewhere?
Please sign in to leave a comment.
Please can you elaborate on this? what do you mean saying that it doesn't find your node_modules?
Sure,
This is a small drill app I am writing in react.
In essence IJ says the module is not installed, but it is, it's just at another path.
My node_modules is inside "build/node_modules", how to say IJ my modules are there?
If I create a junction in the modules folder pointing to "build/node_modules" then autocompletion works seamlessly... is there another way to do it?
Well... IDEA just follows Node.js rules for mpodules resolving. Node.js starts from file parent dir, adding `node_modules` to it, and then, if module is not found there, it moves to the parent directory, and so on, until the root of the file system is reached (see https://nodejs.org/api/modules.html#modules_loading_from_node_modules_folders). But, when doing this, it doesn't inspect the parent folder siblings. If your file is located in project dir/src, project dir/build won't be traversed
You can use
NODE_PATH
to specify a different location:- Run | Edit Configurations..., expand Templates node
- select Node.js configuration, specify
NODE_PATH
in Environment variables fieldPlease see comments in https://youtrack.jetbrains.com/issue/WEB-19476
Exactly that's why I needed to put a junction.
The problem is that I am not in a node.js project, I am in a static web project which worries only about the front-end. At the backend I don't use Node.js.
your static web project still uses node_modules and relies on common rules to resolve them
sometimes we can't control the location of node_modules :(