简体   繁体   English

如何让节点子路径导入智能感知工作

[英]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.

相关问题 如何让雪包查看 package 内部的子路径 - How to get snowpack to look inside a package for subpath Typescript Intellisense 在使用@path 根目录导入时不起作用 - Typescript Intellisense not working when using @ path root directory imports 如何在带有节点的子路径中读取原始 HTTP 响应? - How can I read the raw HTTP response in a subpath with node? 如何让 VS Code 智能感知在多个 node_modules 文件夹中搜索打字稿 - How to get VS Code intellisense to search multiple node_modules folders for typescript 如何使用Node / Gulp连接JavaScript导入 - How to concat javascripts imports with Node/Gulp @ types / node和VS代码:由于注释格式,IntelliSense无法正常工作 - @types/node and VS Code: IntelliSense not working because of comment formatting 通配符导入在 es2020 的 node14 中不起作用 - Wildcard imports not working in node14 with es2020 有没有办法宣传节点的功能并通过Typescript获得智能感知? - Is there any way to promisify node's functions and get intellisense with Typescript? 如何在Node-RED节点中使用NPM导入? - How to use NPM imports in a Node-RED node? 使用 `target: node` 时,如何说服 webpack 使用节点导入而不是 web 导入 - How do I convince webpack to use the node imports over web imports when using `target: node`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM