10

Recently, i started using subpath imports in my node project for mainly my utilities directory. It allowed me to go from

const { promptMessage } = require('../../../../utils/promptMessage.js');

to

const { promptMessage } = require('#utils/promptMessage.js');

The problem i have however, is that my intellisense is no longer working. I found some things with jsconfig.json, but those only seem to work on import statements, not require(). Is there a way to get intellisense with subpath imports?

Maxim
  • 397
  • 1
  • 20

2 Answers2

16

In combination with the imports in package.json i was able to get back intellisense by creating a jsconfig.json file looking like this:

{
    "compilerOptions": {
        "baseUrl": ".",
        "paths": {
            "#utils/*": ["./utils/*"],
            "#database/*": ["./database/*"],
            "#file": ["./dir/file.js"],
            "#colors": ["./commanddata/colors.json"]
        }
    }
}
Maxim
  • 397
  • 1
  • 20
0

I'm late to the party, but I wanted to toss in this Additional note for vscode, in typescript projects:

I found joy by adding the "paths" notation to my tsconfig.json, thus:

Note that I use a root "#base" notation. Ymmv.

{
  "compilerOptions": {
    
    "paths": {
      "#base/*": ["./src/*"]
    }

  }
}

vscode, with this entry in my tsconfig.json, doesn't even need the jsonconfig.json file present.

alllballls
  • 21
  • 2
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/34681608) – Amolgorithm Jul 17 '23 at 05:11