【问题标题】:Module error when styling react components with react-style使用 react-style 样式化 react 组件时出现模块错误
【发布时间】:2016-02-11 23:29:10
【问题描述】:

我对使用 react-style 很感兴趣。虽然尝试在 Gulp 中处理我的文件时出现错误。我收到以下错误:

错误:无法从“/Users/nnnnnn/Google Drive/Code/reactTesting/reactTestOne/node_modules/react-style/lib”中找到模块“react/lib/ExecutionEnvironment”

jsx 文件在这里,以防我做了一些非常愚蠢的事情:

import React, {Component, PropTypes} from 'react';
var ReactDOM = require('react-dom');
var Stylesheet = require('react-style');

export default class ToDo extends React.Component {
    constructor(props){
        super(props);
    }

    componentDidMount() {
        var node = ReactDOM.findDOMNode(this);
        TweenLite.to(node, 0.5, {css:{opacity:1, x:100}, ease:Power4.easeOut});
    }

    render() {
        return (
            <div styles={[styles.todo]} onClick={this.props.onClick} >
                {this.props.text}
            </div>
        )
    }
}

ToDo.propTypes = {
    onClick: PropTypes.func.isRequired,
    text: PropTypes.string.isRequired,
    completed: PropTypes.bool.isRequired
}

var styles = Stylesheet.create({
    todo: {
        opacity: 0,
        x: -100
    }
})

Google 没有提供帮助。想知道我是否需要以某种方式编译包,很累,所以可能是时候离开它过夜了。但是在完成之前努力放手。你知道它是怎么回事:)

干杯。

【问题讨论】:

    标签: reactjs npm npm-install


    【解决方案1】:

    答案是混合编辑文件,如下所示:

    https://github.com/js-next/react-style/pull/128/files

    但在我的实例中编辑:

    var hyphenateStyleName = require('fbjs/lib/hyphenateStyleName');
    

    在stylesToCSS.js 中:

    var hyphenateStyleName = require('react/node_modules/fbjs/lib/hyphenateStyleName');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-27
      • 2020-09-26
      • 2020-08-02
      • 2021-05-26
      • 2018-11-09
      • 2021-09-06
      • 2020-02-24
      • 2018-03-23
      相关资源
      最近更新 更多