Go to declaration of scoped Npm Package
In our project we have centralized some libraries, under ./libraries/**
in different services, like ./service/authentication , we mount those libraries under the docker container node_modules folder.
I want to be able to CMD+CLICK and navigate to these packages. The problem is that Webstorm doesn't know how to locate those packages, because 1) they're not in the local node_modules folder (they're only mounted with Docker) and 2) those packages are scoped, so for example:
"dependencies": {
"@organization-name-project/data-models": "4.16.0",
"@organization-name-project/logger": "2.5.7",
}
How can I tell Webstorm that @organization-name-project should point to a specific directory?
Please sign in to leave a comment.
WebStorm doesn't have problems resolving scoped packages, but, indeed, it won't find packages located outside of project node_modules folder. How do you link these packages to your project? Node.js itself doesn't normally look for a module in a docker container when you require it:). Are you using NODE_PATH environment variable?
What I did was mark the directory in question as a library root from Libraries.
But still Webstorm can't link/Go to Declaration for those packages...
Adding files to JavaScript Libraries won't help here - when resolving required node modules, WebStorm uses the same rules as Node.js, i.e. you should have your modules located in project node_modules folder
I see. No hope then :( Yes I don't know how we do it with docker but we use volumes etc and mount it after the docker container is up.
You can try using NODE_PATH variable pointing to your modules location - it can be set in Node.js default run configuration: Run | Edit Configurations..., expand Templates node, select Node.js configuration, specify
NODE_PATHin Environment variables fieldPlease see comments in https://youtrack.jetbrains.com/issue/WEB-19476
But, of course, it won't work if specified path can't be resolved (for example, if the volumes are not mounted, etc.)
Thanks Elena, that indeed seems relative, I added NODE_PATH=libraries in the node.js template but it doesn't seem to be doing something.