【问题标题】:VSCode eslint error in IDE but not in CLIIDE 中的 VSCode eslint 错误,但 CLI 中没有
【发布时间】:2018-11-23 21:15:11
【问题描述】:

我在 VScode 中有绝对导入,在 CLI 中使用 eslint 构建和运行良好,但在 VSCode 中没有。

下图是vscode中的错误和linter的输出。

我还有一个 jsconfig.json 文件,其中包含以下内容:

{
  "compilerOptions": {
    "target": "ES6",
    "module": "commonjs",
    "baseUrl": "./src",
    "paths": {
      "*": ["*"],
      "components/*": ["components/*"],
      "redux/*": ["redux/*"]
    }
  },
  "include": ["src"]
}

关于如何让 VSCode 解析导入并因此让 Intellisense 工作的任何想法?

【问题讨论】:

  • 你并不孤单,也许这会有所帮助github.com/Microsoft/vscode/issues/14907
  • 很奇怪,我刚刚检查了我的机器,你的配置对我来说很好,并且没有产生错误。 VsCode 1.24.0,节点 7.9.0
  • @Vitalii 是的,已经检查过了,但遗憾的是没有解决问题:-(

标签: javascript reactjs visual-studio-code eslint


【解决方案1】:

如果componentspagesredux 是您的本地文件夹,请尝试添加./ 作为它们的前缀。

import {Header} from './components';
import {Home} from './pages';

这会通知 linter 我们正在寻找相对导入,而不是来自 node_modules

【讨论】:

  • OP 在他/她的jsconfig.json 中配置了baseUrl。绝对路径应该没有任何问题
猜你喜欢
  • 2021-12-28
  • 2020-10-27
  • 1970-01-01
  • 2020-06-05
  • 2019-05-02
  • 2018-12-14
  • 2021-08-11
  • 1970-01-01
  • 2020-08-21
相关资源
最近更新 更多