【问题标题】:Parsing error: Argument for '--jsx' option must be: 'preserve', 'react-native', 'react'解析错误:“--jsx”选项的参数必须是:“preserve”、“react-native”、“react”
【发布时间】:2021-05-11 11:02:31
【问题描述】:

我正在学习 firebase 云功能,在我的 index.ts 文件夹中,我在 import

下突出显示了错误消息

我不知道这意味着什么以及如何解决它最糟糕的是,相同的代码在 youtube 上的 firebase 教程视频中工作

这段代码有什么问题?

import * as functions from "firebase-functions";

// Start writing Firebase Functions
// https://firebase.google.com/docs/functions/typescript

export const helloWorld = functions.https.onRequest((request, response) => {
  functions.logger.info("Hello logs!", { structuredData: true });
  response.send("Hello from Firebase!");
});

这是我的 tsconfig

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "es2017"
  },
  "compileOnSave": true,
  "include": ["src"]
}

【问题讨论】:

  • 你能发布你的 tsconfig 文件吗?
  • 我加了,我觉得和你的一样
  • 您的index.ts 在src 目录中吗?
  • 是的,它在src 目录中

标签: reactjs typescript firebase visual-studio-code


【解决方案1】:

很可能,您的tsconfig 文件中有错误。具体来说,您可能有一个明确的选项,称为jsx。我猜你实际上不需要为你的 Firebase 云函数解析 JSX,但我可能是错的。

这是我的 tsconfig 用于 Firebase 云的示例,它可以工作(当然,您可能需要稍微不同的选项):

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "es2017",
  },
  "compileOnSave": true,
  "include": [
    "src"
  ]
}

您的src 目录也可能没有指向您的 Typescript 源文件的位置。

最后,VSCode 可能对您的 Typescript 设置做出了不正确的假设——这可能是因为您没有 tsconfig 文件,或者因为 VSCode 使用的 Typescript 版本与您的项目不同.在此处查看可能的解决方案:Problem with Visual Studio Code using "react-jsx" as jsx value with create-react-app

引用此错误的其他一些资源:

【讨论】:

  • 我认为问题在于我的 eslint 设置,但我也从未真正更改过它们。我只是不明白,为什么我在 firebase 自动生成的文件夹上收到这么多 ESLINT 错误?
  • 您的 eslint 设置很可能是 VSCode 全局默认值,而不是特定于 firebase 项目(除非您的 firebase 目录中有 linter 配置文件)
  • 您是否查看了以下列出的所有解决方案:stackoverflow.com/questions/64974648/…
【解决方案2】:
{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "es2017",
    "jsx": "react"
  },
  "compileOnSave": true,
  "include": ["src"]
}

在compilerOptions中添加“jsx”:“react”

【讨论】:

    【解决方案3】:

    如果您的设置是包含多个软件包的 monorepo,则问题可能是由多个不同版本的 typescript 引起的。我在几个包中有 2 个不同的主要版本。当我将它们统一为一个时,错误就消失了。

    或者可能是您的编辑器的打字稿版本与项目as depicted here

    【讨论】:

      猜你喜欢
      • 2021-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-17
      • 1970-01-01
      • 2023-02-16
      • 2023-01-21
      • 2017-07-27
      相关资源
      最近更新 更多