Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Gatsby Error ReferenceError:从JSX迁移到Typescript时未定义React_Node.js_Reactjs_Typescript_Gatsby - Fatal编程技术网

Node.js Gatsby Error ReferenceError:从JSX迁移到Typescript时未定义React

Node.js Gatsby Error ReferenceError:从JSX迁移到Typescript时未定义React,node.js,reactjs,typescript,gatsby,Node.js,Reactjs,Typescript,Gatsby,我有一个盖茨比项目,我想从JSX迁移到Typescript。我遵循这一点来实现这一目标 Typescript的配置如下所示: import React, { useState } from "react"; tslint.json: { "rulesDirectory": "tslint-plugin-prettier", "extends": ["tslint:latest",

我有一个盖茨比项目,我想从JSX迁移到Typescript。我遵循这一点来实现这一目标

Typescript的配置如下所示:

import React, { useState } from "react";
tslint.json

{
    "rulesDirectory": "tslint-plugin-prettier",
    "extends": ["tslint:latest", "tslint-react", "tslint-config-prettier"],
    "rules": {
        "prettier": true,
        "jsx-no-multiline-js": false,
        "jsx-no-lambda": false,
        "import-name": false,
        "no-boolean-literal-compare": false
    }
}
{
    "compilerOptions": {
      "outDir": "./built",
      "allowJs": true,
      "target": "es5"
    },
    "include": ["./src/**/*"]
}
...
"type-check": "tsc --noEmit",
"lint": "tslint --project ."
...
tsconfig.json

{
    "rulesDirectory": "tslint-plugin-prettier",
    "extends": ["tslint:latest", "tslint-react", "tslint-config-prettier"],
    "rules": {
        "prettier": true,
        "jsx-no-multiline-js": false,
        "jsx-no-lambda": false,
        "import-name": false,
        "no-boolean-literal-compare": false
    }
}
{
    "compilerOptions": {
      "outDir": "./built",
      "allowJs": true,
      "target": "es5"
    },
    "include": ["./src/**/*"]
}
...
"type-check": "tsc --noEmit",
"lint": "tslint --project ."
...
package.json

{
    "rulesDirectory": "tslint-plugin-prettier",
    "extends": ["tslint:latest", "tslint-react", "tslint-config-prettier"],
    "rules": {
        "prettier": true,
        "jsx-no-multiline-js": false,
        "jsx-no-lambda": false,
        "import-name": false,
        "no-boolean-literal-compare": false
    }
}
{
    "compilerOptions": {
      "outDir": "./built",
      "allowJs": true,
      "target": "es5"
    },
    "include": ["./src/**/*"]
}
...
"type-check": "tsc --noEmit",
"lint": "tslint --project ."
...
gatsby config.js

module.exports = {
    plugins: [
        'gatsby-plugin-tslint', // TSLint
        // TS Plugin. Gatsby already ships with TS
        {
            resolve: 'gatsby-plugin-typescript',
            options: {
              isTSX: true, // defaults to false
              jsxPragma: 'jsx', // defaults to "React"
              allExtensions: true, // defaults to false
            },
        }
    ]
};
当我运行《盖茨比开发》时,出现以下错误:

error There was an error compiling the html.js component for the development server.

See our docs page on debugging HTML builds for help https://gatsby.dev/debug-html ReferenceError: React is not defined

  18 |             next: function (result) {
  19 |                 if (_this.lastError || _this.isDifferentFromLastResult(result)) {
> 20 |                     _this.updateLastResult(result);
     | ^
  21 |                     iterateObserversSafely(_this.observers, 'next', result);
  22 |                 }
  23 |             },


  WebpackError: ReferenceError: React is not defined
我使用ES5格式的React导入,如下所示:

import React, { useState } from "react";