简体   繁体   English

Vscode Path Intellisense 不适用于 jsconfig.json(下一个 js)

[英]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,那是,

  • Stop server停止服务器
  • Restart VSCode重启 VSCode
  • Start server启动服务器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 jsconfig.json 中使用 baseUrl 不适用于 Next.js - Using baseUrl in jsconfig.json is not working with Next.js Visual Studio 代码“Cick-Through / Go-To”不适用于 jsconfig.json(和 Next.js)中的路径别名 - Visual Studio Code “Cick-Through / Go-To” does not work with path aliases in jsconfig.json (and Next.js) 什么是jsconfig.json? - What is jsconfig.json? 在VSCode中,如何正确配置jsconfig.json以便使用index.js导入的绝对路径起作用? - In VSCode how to properly configure jsconfig.json in order for absolute paths with index.js imports to work? vscode在jsconfig.json文件中显示typescript相关问题 - vscode shows typescript related problems in jsconfig.json file jsconfig.json 路径在导入 function 时不起作用 - jsconfig.json paths not working when importing function eslint 使用路径映射配置 jsconfig.json 解决导入错误 - eslint resolve error on imports using with path mapping configured jsconfig.json 我的 jsconfig.json 在反应 js 中出现错误,在 position 的 JSON 中说 throw err Unexpected token } - I have an error with my jsconfig.json in react js says throw err Unexpected token } in JSON at position 在 VueJS 项目中设置 jsconfig.json - set jsconfig.json in a VueJS project Typescript,jsconfig.json,bower.json和vs代码一起工作 - typescript, jsconfig.json, bower.json and vs-code working together
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM