0

您好我正在创建一个 SPFX 天气 webpart,我收到此错误:

在此处输入图像描述

当我运行 gulp build 时没有错误。我不确定如何调试我的问题。这是我遇到问题的 proptypes.shape() 的片段:

import * as React from 'react';
import PropTypes from 'prop-types';
    export const Day: React.SFC<any> = props => {
      const date = props.day.dt;
      const icon = getIcon(props.day.weather[0].id);
      const animate = true;
      const iconSize = 64;
      const iconColor = 'black';
      return (
        <div className={appClasses.dayContainer} onClick={props.onClick} role="link">
            <h2 className={appClasses.date}>{(new Date(date * 1000)).toDateString()} - {(new Date(date * 1000)).toLocaleTimeString()}</h2>
           <ReactAnimatedWeather
                icon={icon}
                color={iconColor}
                size={iconSize}
                animate={animate}
            />
        </div>
      );
    };

    Day.defaultProps = {
      onClick: () => {},
    };

    Day.propTypes = {
      day: PropTypes.shape({
        dt: PropTypes.number.isRequired,
        weather: PropTypes.array.isRequired,
      }).isRequired,
      onClick: PropTypes.func,
    };

我想指出,我首先使用 react 创建了 webpart,它运行良好,但是当我创建一个 SPFX 应用程序并将我现有的代码转移到其中时。我遇到过这些错误。

这是我的 package.json

{
  "name": "spfx-weather-2",
  "version": "0.0.1",
  "private": true,
  "engines": {
    "node": ">=0.10.0"
  },
  "dependencies": {
    "@microsoft/sp-core-library": "~1.1.0",
    "@microsoft/sp-webpart-base": "~1.1.1",
    "@types/react": "0.14.46",
    "@types/react-addons-shallow-compare": "0.14.17",
    "@types/react-addons-test-utils": "0.14.15",
    "@types/react-addons-update": "0.14.14",
    "@types/react-dom": "0.14.18",
    "@types/webpack-env": ">=1.12.1 <1.14.0",
    "prop-types": "^15.6.1",
    "react": "15.4.2",
    "react-animated-weather": "^1.0.3",
    "react-dom": "15.4.2",
    "react-router-dom": "^4.2.2"
  },
  "devDependencies": {
    "@microsoft/sp-build-web": "~1.1.0",
    "@microsoft/sp-module-interfaces": "~1.1.0",
    "@microsoft/sp-webpart-workbench": "~1.1.0",
    "gulp": "~3.9.1",
    "@types/chai": ">=3.4.34 <3.6.0",
    "@types/mocha": ">=2.2.33 <2.6.0"
  },
  "scripts": {
    "build": "gulp bundle",
    "clean": "gulp clean",
    "test": "gulp test"
  }
}
4

1 回答 1

0

在这里查看我的答案[SPLoaderError.loadComponentError]: ***Failed to load component

你很可能有同样的问题。如果您要发布您的 github 链接供我克隆,我可以为您确认。

TL;博士

您的工厂之间可能有循环引用。您需要将所需的任何代码从顶级工厂移动到所述工厂的底部。

如果您在阅读我的其他答案后不太明白,请告诉我。

于 2018-05-08T15:34:49.743 回答