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