[英]Module not found: Can't resolve 'child_process'
while using reactjs I am getting this.webpack error incounter while npm start. 在使用reactjs时,我在npm启动时遇到了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} />
);
}
});
File : GoogleChart.jsx : This file contains the import statement for including CsvRead.jsx but not working while including this file. File:GoogleChart.jsx:该文件包含用于包含CsvRead.jsx的导入语句,但在包含此文件时不起作用。
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);
Anyone can help me on this.might not getting correct issue to resolve this problem. 任何人都可以在此方面为我提供帮助。可能无法获得正确的问题来解决此问题。 How to solve this issue?
如何解决这个问题?
csvtojson
package is trying to spawn a child_process, which cannot be done in a browser. csvtojson
软件包正在尝试生成child_process,这无法在浏览器中完成。 According to the doc, if you pass a { fork: false }
in the options, it won't use child_process. 根据文档,如果您在选项中传递了
{ fork: false }
,它将不会使用child_process。 Please paste your code. 请粘贴您的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.