reactjs – 最简单的Typescript React WebPack示例生成错误
发布时间:2020-12-15 09:35:13 所属栏目:百科 来源:网络整理
导读:当我编译一个简单的React / Typescript应用程序(如下所示)时,我得到了各种编译器警告,这些警告似乎不在我的代码中. /// reference path="main/ambient/react-dom/index.d.ts" //// reference path="main/ambient/react/index.d.ts" /import * as React from
当我编译一个简单的React / Typescript应用程序(如下所示)时,我得到了各种编译器警告,这些警告似乎不在我的代码中.
/// <reference path="main/ambient/react-dom/index.d.ts" /> /// <reference path="main/ambient/react/index.d.ts" /> import * as React from "react"; import { render } from "react-dom"; class Example extends React.Component<any,any> { render() { return <p> Hello! </p>; } } render(<Example />,document.getElementById("root")); 虽然此示例在编译后运行(通过WebPack),但它会生成以下错误: (19,22): error TS2339: Property 'createElement' does not exist on type '{}'. (22,9): error TS2339: Property 'Component' does not exist on type '{}'. (23,13): error TS2339: Property 'render' does not exist on type '{}'. (23,26): error TS2339: Property 'createElement' does not exist on type '{}'. 我正在运行React v0.14.8.我正在使用这些typings for React和这些typings for React-dom.enter link description here 我的问题是:为什么这个例子会产生这么多错误?我该如何解决这些错误? 请求:tsconfig.json { "compilerOptions": { "target": "es5","module": "commonjs","jsx": "react" },"exclude": [ "node_modules","typings/browser","typings/browser.d.ts" ],"compileOnSave": false,"buildOnSave": false } 解决方法
我找到了解决方案.这些错误是由WebPack中的插件引起的(新的webpack.optimize.OccurenceOrderPlugin()).删除此插件解决了这个问题.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |