VSCode is not offering import suggestions correctly for a package that was linked locally (using npm link).
Normally when I want to use a class from a package, I'd write Foo and press tab to automatically add the import for myModule/Foo.js. But in my current setup, I am not getting import suggestions for myModule at all.
My folder structure looks like this:
project
|- server (node package)
| |- node_modules/
| |- src/
| |- package.json
|- myModule (node package)
|- src/
|- package.json
All packages are of the module type (es6 import/exports).
"type": "module"
The myModule package uses a subpath export to hide the src folder:
"exports": {
"./*": "./src/*"
}
Then I used npm link in project/myModule, followed by npm link myModule in project/server.
I can then use myModule in server/src/index.js as follows:
import Foo from "myModule/Foo.js"
import Four from "myModule/Bar/Four.js"
At this point, Node is happy. Unfortunately, VSCode is not. When using Foo or Bar and using the IntelliSense suggestion to automatically add the import, I get the following result:
../../myModule/src/Foo.js) if I remove the subpath export from myModule.jsconfig.json with a path alias like: "myModule/*": ["./node_modules/myModule/src/*"] or "myModule/*": ["./node_modules/myModule/*"] but unfortunately that didn't make a difference.What can I do to have working import suggestions again in VSCode?
Placing a jsconfig.json in project/ with "myModule/*": ["./myModule/src/*"] as a path alias has made VSCode happy again.
This may present other challenges further down the line, as I'm now specifying this alias for every package in project/. Other suggestions are still very much welcome, as well as an explanation why jsconfig.json in project/server/ was not working as expected.