【问题标题】:Go to definition for .jsx does not work转到 .jsx 的定义不起作用
【发布时间】:2018-01-18 04:32:53
【问题描述】:

我在 Visual Studio Code 中使用 es6 语法,当我导入普通文件时,我可以单击 F12(转到定义),它工作得很好。问题是组件(从 .jsx 文件导入)根本不起作用(单击go to definition 时没有任何反应)。有谁知道如何修复它?

附:我有 jsconfig.json 这样的允许正确转到普通 .js 文件的定义:

{
    "compilerOptions": {
        "target": "ES6"
    },
    "exclude": [
        "node_modules"
    ]
}

【问题讨论】:

标签: reactjs visual-studio-code react-jsx


【解决方案1】:

虽然您可以从其中一个 cmets 中提到的github issues 找到解决方案,但我想让 SO 用户更容易使用它。引用自 Github 问题页面:

简单的解决方法是添加 compilerOption "jsx": "preserve" (或 “jsx”:“react”或“jsx”:“react-native”)

jsconfig.json:

{
    "compilerOptions": {
        "jsx": "react"
    }
}

【讨论】:

  • 你可以在你的Javascript项目的根目录下创建jsconfig.json
  • 如果 "jsx": "react" 不起作用然后检查你的路径是否正确映射。
猜你喜欢
  • 1970-01-01
  • 2019-11-04
  • 2020-02-05
  • 1970-01-01
  • 2016-01-16
  • 2022-01-06
  • 1970-01-01
  • 2018-10-20
  • 1970-01-01
相关资源
最近更新 更多