Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.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/9/ssl/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
Reactjs 带有React类型的TypeScript将不会编译_Reactjs_Typescript_Webpack_Typescript Typings - Fatal编程技术网

Reactjs 带有React类型的TypeScript将不会编译

Reactjs 带有React类型的TypeScript将不会编译,reactjs,typescript,webpack,typescript-typings,Reactjs,Typescript,Webpack,Typescript Typings,我尝试按照TypeScript上的设置进行操作,但出现了几个错误。这是我的文件: tsconfig: { "compilerOptions": { "outDir": "../scripts/", "noImplicitAny": false, "noEmitOnError": true, "removeComments": true, "sourceMap": true, "target": "es5", "jsx": "react"

我尝试按照TypeScript上的设置进行操作,但出现了几个错误。这是我的文件:

tsconfig:

{
  "compilerOptions": {
    "outDir": "../scripts/",
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": true,
    "sourceMap": true,
    "target": "es5",
    "jsx": "react",
    "lib": [
      "es6",
      "es5",
      "dom"
    ]
  },
  "exclude": [
    "node_modules",
    "wwwroot",
    "scripts"
  ]
}
package.json:

{
  "version": "1.0.0",
  "name": "asp.net",
  "private": true,
  "devDependencies": {
    "@types/react": "latest",
    "@types/react-dom": "latest",
    "typescript": "2.4.2",
    "awesome-typescript-loader": "3.2.3",
    "source-map-loader": "0.2.1",
    "gulp": "3.9.1",
    "del": "2.2.2",
    "gulp-concat": "2.6.1",
    "gulp-sourcemaps": "2.6.0",
    "gulp-uglify": "2.1.2",
    "@types/jquery": "2.0.41",
    "pump": "1.0.2",
    "@types/bootstrap": "3.3.33",
    "gulp-typescript": "3.1.7",
    "@types/knockout": "3.4.41",
    "ts-loader": "2.3.2",
    "webpack": "3.5.4",
    "webpack-stream": "4.0.0"
  },
  "dependencies": {
    "react": "latest",
    "react-dom": "latest"
  }
}
webpack.config.js:

module.exports = {
    entry: "./typescripts/index.tsx",
    output: {
        filename: "bundle.js",
        path: __dirname + "/scripts"
    },
    devtool: "source-map",    
    resolve: {
        extensions: [".ts", ".tsx", ".js", ".json"]
    },    
    module: {
        rules: [
            { test: /\.tsx?$/, loader: "awesome-typescript-loader" },
            { enforce: "pre", test: /\.js$/, loader: "source-map-loader" }
        ]
    },
    externals: {
        "react": "React",
        "react-dom": "ReactDOM"
    }
我的tsx文件是从上面链接的页面复制/粘贴的

我遇到的第一个错误是
awesome typescript loader

ERROR in ./typescripts/index.tsx
Module parse failed: c:\Documents\Visual Studio 2017\Projects\DevSln\WebApplication4\node_modules\awesome-typescript-loader\dist\entry.js!C:\Documents\Visual Studio 2017\Projects\DevSln\WebApplication4\typescripts\index.tsx Unexpected token (6:16)
You may need an appropriate loader to handle this file type.
| var ReactDOM = require("react-dom");
| var Hello = require("./hello");
| ReactDOM.render(<Hello.Hello compiler="typescript" framework="React"/>, document.getElementById("example"));
| 

这妨碍了我构建解决方案。我正在使用VS2017。非常感谢您的帮助。

我不知道这是不是正确的答案,但它很有效,而且我没有丢失打字。为了修复它,我删除了
“@types/react”:“latest”
“@types/react dom:”packages.json中的“最新”

Severity    Code    Description Project File    Line    Suppression State
Error       Build:Module '"C:/Documents/Visual Studio 2017/Projects/DevSln/WebApplication4/node_modules/@types/react/index"' has no exported member 'DOMAttributes'.    WebApplication4 C:\Documents\Visual Studio 2017\Projects\DevSln\WebApplication4\node_modules\@types\react-dom\index.d.ts    15