[英]Using baseUrl in jsconfig.json is not working with Next.js
[英]Vscode Path Intellisense not working with jsconfig.json (next js)
我的项目结构是这样的:
jsconfig.json
next.config.json
components
|_atoms
|_Button.jsx
|_Button.module.scss
|_...
|_...
...
在jsconfig.json
里面,我有这个:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/components/*": ["components/*"]
}
},
"include": ["components/**/*", "api/**/*", "data/**/*", "pages/**/*", "utils/**/*"]
}
Next.js 正确导入组件并且它正在工作,但在开发方面,自动完成不再工作了!
例如,所有这些导入语句都像魅力一样工作,但我手动编写了路径并且自动完成没有帮助:
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
所以 next js 没有问题,但是Path Intellisense不再建议文件名了。
我将jsconfig.json
重命名为其他内容(以禁用它),这一次,Path Intellisense 工作正常,但下一个 js 无法导入组件。
我怎样才能从两者中受益? 我想要绝对导入并且还使用 Path Intellisense。
如果您刚刚创建了一个新的jsconfig.json
(或tsconfig.json
)文件,或者对其进行了更改,则需要执行以下操作才能使其正常工作:
重新启动服务器(用于 nextjs)。 重新启动 VSCode(用于自动完成)。
那是,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.