[英]Vscode Path Intellisense not working with jsconfig.json (next js)
My project structure is like this:我的项目结构是这样的:
jsconfig.json
next.config.json
components
|_atoms
|_Button.jsx
|_Button.module.scss
|_...
|_...
...
and inside the jsconfig.json
, I have this:在jsconfig.json
里面,我有这个:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/components/*": ["components/*"]
}
},
"include": ["components/**/*", "api/**/*", "data/**/*", "pages/**/*", "utils/**/*"]
}
Next.js correctly imports the components and it's working, but on the developing side, autocomplete isn't working anymore! Next.js 正确导入组件并且它正在工作,但在开发方面,自动完成不再工作了!
for example, all of these import statements are working like a charm, but I manually wrote the path and autocomplete didn't help:例如,所有这些导入语句都像魅力一样工作,但我手动编写了路径并且自动完成没有帮助:
import Button from "components/atoms/Button"; //works
import Button from "@/components/atoms/Button"; //works
import Button from "../components/atoms/Button"; //works if the relative path is correct
import styles from "./Button.module.scss"; //works inside Button.jsx
So there's no problem with next js, but Path Intellisense isn't suggesting filenames anymore.所以 next js 没有问题,但是Path Intellisense不再建议文件名了。
I renamed jsconfig.json
to something else (to disable it) and this time, Path Intellisense works correctly, but next js can't import components.我将jsconfig.json
重命名为其他内容(以禁用它),这一次,Path Intellisense 工作正常,但下一个 js 无法导入组件。
How can I benefit from both?我怎样才能从两者中受益? I want to have absolute imports and also use Path Intellisense.我想要绝对导入并且还使用 Path Intellisense。
If you just created a new jsconfig.json
(or tsconfig.json
) file, or made changes to it, you'll need to do the following to get it to work properly:如果您刚刚创建了一个新的jsconfig.json
(或tsconfig.json
)文件,或者对其进行了更改,则需要执行以下操作才能使其正常工作:
Restart server (for nextjs).重新启动服务器(用于 nextjs)。 Restart VSCode (for autocomplete).重新启动 VSCode(用于自动完成)。
That is,那是,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.