相关疑难解决方法(0)

使用“react-jsx”作为带有 create-react-app 的 jsx 值的 Visual Studio Code 问题

我正在努力解决 VSCode 中的“错误”:

Argument for '--jsx' option must be: 'preserve', 'react-native', 'react'
Run Code Online (Sandbox Code Playgroud)

因此,当value 似乎有效时,react-scripts (create-react-app) 会自动将jsxkey设置为react-jsxvalue react

实际上,代码运行良好并显示了我想要的页面,但是 IDE 将所有内容都强调为错误,并说:

Cannot use JSX unless the '--jsx' flag is provided.
Run Code Online (Sandbox Code Playgroud)

这是我的 tsconfig.json :

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": [
    "src"
  ]
} …
Run Code Online (Sandbox Code Playgroud)

jsx typescript tsconfig visual-studio-code create-react-app

73
推荐指数
3
解决办法
2万
查看次数

除非提供'--jsx'标志,否则无法使用JSX

我已经四处寻找解决这个问题的方法了.所有这些都建议添加"jsx": "react"到您的tsconfig.json文件.我做了什么.另外一个是补充"include: []",我也做了.但是,当我尝试编辑.tsx文件时,我仍然收到错误.下面是我的tsconfig文件.

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "allowJs": true,
        "checkJs": false,
        "jsx": "react",
        "outDir": "./build",
        "rootDir": "./lib",
        "removeComments": true,
        "noEmit": true,
        "pretty": true,
        "skipLibCheck": true,
        "strict": true,
        "moduleResolution": "node",
        "esModuleInterop": true
    },
    "include": [
        "./lib/**/*"
    ],
    "exclude": [
        "node_modules"
    ]
}
Run Code Online (Sandbox Code Playgroud)

任何的意见都将会有帮助.我正在使用babel 7来编译env,react和typescript预设的所有代码.如果你们需要更多文件来帮助调试这个,请告诉我.

jsx typescript reactjs tsx

36
推荐指数
13
解决办法
2万
查看次数

解析错误:“--jsx”选项的参数必须是:“preserve”、“react-native”、“react”

我正在学习 firebase 云函数,在我的index.ts文件夹中,我在导入下突出显示了错误消息

我不知道这意味着什么以及如何解决它,最糟糕的是,相同的代码在 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!");
});

Run Code Online (Sandbox Code Playgroud)

这是我的 tsconfig

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "es2017"
  },
  "compileOnSave": true,
  "include": ["src"]
}
Run Code Online (Sandbox Code Playgroud)

firebase typescript reactjs visual-studio-code

10
推荐指数
1
解决办法
6253
查看次数

出现错误 TS17004:除非提供“--jsx”标志,否则无法使用 JSX

嘿伙计们,这个问题还没有通过类似的解决,

\n
    \n
  1. 构建:除非提供“--jsx”标志,否则无法使用 JSX
  2. \n
  3. 除非提供“--jsx”标志,否则无法使用 JSX
  4. \n
\n

尝试了他们的解决方案,但对我不起作用。

\n

现在我的情况\n tsconfig.js

\n
{\n    "compilerOptions": {\n        "noUnusedLocals": false,\n        "noUnusedParameters": false,\n        "noImplicitReturns": false,\n        "noImplicitAny": false,\n        "skipLibCheck": false,\n        "strict": false,\n        "strictNullChecks": false,\n        "allowSyntheticDefaultImports": true,\n        "esModuleInterop": true,\n        "resolveJsonModule": true,\n        "experimentalDecorators": true,\n        "emitDecoratorMetadata": true,\n        "declaration": true,\n        "jsx": "react",\n        "module": "commonjs",\n        "moduleResolution": "node",\n        "target": "es6",\n        "outDir": "./dist",\n        "lib": [\n            "dom",\n            "esnext"\n        ]\n    },\n    "esModuleInterop": true,\n    "include": [\n        "src/components/canvas/index.tsx",\n        "src/components/canvas/Canvas.tsx",\n        "src/components/canvas/global.d.ts"\n    ],\n    "exclude": [\n        "node_modules",\n        "dist",\n        "lib"\n    ]\n}\n\n
Run Code Online (Sandbox Code Playgroud)\n

gulpfile.js

\n
\nconst gulp …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs gulp tsconfig babeljs

9
推荐指数
1
解决办法
2万
查看次数