找不到模块:无法解析'child_process'

时间:2017-09-26 11:26:04

标签: node.js reactjs npm

在使用reactjs时,我在npm start时遇到this.webpack错误。

    `./~/csvtojson/libs/core/workerMgr.js
    Module not found: Can't resolve 'child_process' in '/var/www/html/ReactLogin/node_modules/csvtojson/libs/core'`
    File : CsvRead.jsx

    import React from 'react';
    import ReactDOM from 'react-dom';

    var objects;

    var CsvRead = React.createClass({
        readFile:function(){
            var file = this.refs.file.files[0];
            var reader = new FileReader();
            reader.onload = function(evt){
                 var resultText = evt.target.result;
                 objects = this.csvToJson(resultText);
                 console.log(objects);
            }.bind(this);
            var newFile = file.slice(0,5000);
            reader.readAsText(newFile); 
        },
        csvToJson:function(csvString){
            var Converter = require("csvtojson").Converter;
            var converter = new Converter({});
            converter.fromString(csvString, function(err,result){
               //When i console log the result it is working but when i return The result:
               // i am getting a undefined error
               //console.log(result);
               return result;
            });
        },
        render:function(){
        console.log('i am here');
          return (
             <input type="file" ref="file" onChange={this.readFile} /> 
          );
        }
    });

文件:GoogleChart.jsx:此文件包含用于包含CsvRead.jsx的import语句,但在包含此文件时不起作用。

    import React, { Component } from 'react'
    import ReactDOM from 'react-dom';
    import { connect } from 'react-redux'
    import { createHashHistory } from 'history';
    import { Chart } from 'react-google-charts';
    import { CsvRead } from '../dynamic/CsvRead.jsx'

    const customHistory = createHashHistory();

    class GoogleChart extends Component {
        constructor(props) {
      super(props);
        this.state = {
          options: {
            title: 'Users Hours comparison',
            hAxis: { title: 'User'},
            vAxis: { title: 'Hours'},
            legend: 'none',
            axisTitlesPosition: 'out',
            'isStacked': true,
            colors: ['#0598d8', '#f97263'],
          },

          data :[
            ['User', 'workingHours', 'ExceptedWorkingHours'],
            ['user1', 500, 400],
            ['user2', 300, 200],
            ['user3', 1500, 650],
            ['user4', 1200, 470],
            ['user5', 1000, 700],
            ['user6', 500, 400],
            ['user7', 1300, 500],
            ['user8', 176, 55],
            ['user9', 310, 240],
            ['user10', 500, 400]
        ]
        };
      }

      render() {
        return (
          <CsvRead />
          <Chart
            chartType="ColumnChart"
            data = {this.state.data}
            options={this.state.options}
            graph_id="ColumnChart"
            width="100%"
            height="400px"
            legend_toggle
          />
        );
      }
    }


    function select(state) {
        return {
            users: state.users
        }
    }

    export default connect(select)(GoogleChart);

任何人都可以帮我解决此问题。可能无法解决此问题。 如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

{ fork: false }包正在尝试生成一个child_process,这在浏览器中无法完成。根据文档,如果在选项中传递<script> $(document).ready(function offermessage() { var a = ($('#<%=offermessage.ClientID %> option:selected').val()); if(a==9) { alert("hello"); } }); </script> <div class="col-12"> <asp:DropDownList ID="offermessage" CssClass="farsi-font drp-down-list" required="" runat="server" > <asp:ListItem Value="Baseid">value</asp:ListItem> </asp:DropDownList> </div> ,则不会使用child_process。请粘贴您的代码。