electron 无法解析'child_process'

gzszwxb4  于 2023-01-03  发布在  Electron
关注(0)|答案(1)|浏览(366)

我现在在我的软件的后端,它通过电子运行,但我不能得到数据,所以我试图从一个python程序检索数据,它使用Flask发送它,但当我运行npm start命令时,它给我以下错误消息:

Module not found: Error: Can't resolve 'child_process' in 'C:\Users\cantr\Desktop\Stage ingénieur KOMILFO SPORT\Sail Vision\React\react-electron\src\pages'

下面是我的Javascript和python脚本:
联森:

import React from "react";

class Home extends React.Component {
    constructor() {
        super();
        this.hello = require("child_process").spawn("python", ["./hello.py"]);
        this.state = { fs_s5: 12 };
        this.hello.stdout.on('data', (data) => {
          this.setState({ fs_s5: data });
        });
    }
    render(){
        return(
        <div>
            <div class="home">
                <div class="template-1" id="temp1">
                <div class="panel-1">
                    <div class="panel-header">
                    <h1>Panel 1</h1>
                    <i class='bx bx-cog modal-trigger-panel'></i>
                    </div>
                    <div class="panel-body">
                    <div class="sec-5 modal-trigger-data" id="hs-sec-5">
                        <span class="h1" id="h1-fs-s5">{this.state.fs_s5}</span>
                        <h2>TWIST</h2>
                        <h3>s5</h3>
                    </div>
                    <div class="sec-4 modal-trigger-data" id="hs-sec-4">
                        <h1>--</h1>
                        <h2>TWIST</h2>
                        <h3>s4</h3>
                    </div>
                    <div class="sec-3 modal-trigger-data" id="hs-sec-3">
                        <h1>--</h1>
                        <h2>TWIST</h2>
                        <h3>s3</h3>
                    </div>
                    <div class="sec-2 modal-trigger-data" id="hs-sec-2">
                        <h1>--</h1>
                        <h2>TWIST</h2>
                        <h3>s2</h3>
                    </div>
                    <div class="sec-1 modal-trigger-data" id="hs-sec-1">
                        <h1>--</h1>
                        <h2>TWIST</h2>
                        <h3>s1</h3>
                    </div>
                    </div>
                </div>
                </div>
            </div>
        </div>    
        );
    }
}

export default Home;

巨蟒:

from __future__ import print_function
import time
from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World! This is powered by Python backend."

if __name__ == "__main__":
   print(12)
   time.sleep(5)
   app.run(host='127.0.0.1', port=5000)

此致,

s8vozzvw

s8vozzvw1#

尝试在package.json文件中添加以下内容:

{
  ...
  // add this to package.json 
  "browser": {
    "child_process": false
  }
}

相关问题