[英]How to get node subpath imports intellisense working
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().
我在 jsconfig.json 中发现了一些东西,但那些似乎只适用于导入语句,而不适用于 require()。 Is there a way to get intellisense with subpath imports?
有没有办法通过子路径导入获得智能感知?
In combination with the imports in package.json i was able to get back intellisense by creating a jsconfig.json file looking like this:结合 package.json 中的导入,我能够通过创建一个如下所示的 jsconfig.json 文件来恢复智能感知:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"#utils/*": ["./utils/*"],
"#database/*": ["./database/*"],
"#file": ["./dir/file.js"],
"#colors": ["./commanddata/colors.json"]
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.