【发布时间】:2021-03-10 13:53:59
【问题描述】:
我正在尝试从 js 文件调用 python 文件中的函数,我通过我的控制台让它工作,但我现在正尝试使用 expo 在移动应用程序中实现它。
我的设置方式是,我的应用中有某个屏幕的 JS 文件,然后这会在单独的 JS 文件中调用一个函数,然后调用 python 文件中的函数。
我正在使用child_process 模块从 JS 与 python 对话。
正如我所说,在我尝试将 JS 函数导出到我的屏幕文件之前,这是有效的。
index.js
export function foo(process, sentence){
const spawn = require("child_process").spawn;
const process = spawn("python3", ["./python.py", sentence]);
...
}
screen.js
*other imports
import { foo } from "./filepath..."
...
但是当我运行npm start 时,我收到以下错误:
Failed building JavaScript bundle.
While trying to resolve module `child_process` from file `/Users/mee/Documents/GitHub/project/app/screens/screen.js`, the package `/Users/mee/Documents/GitHub/project/node_modules/child_process/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/Users/me/Documents/GitHub/project/node_modules/child_process/app/screens/screen.js`. Indeed, none of these files exist:
我该如何解决这个问题?
【问题讨论】:
标签: javascript reactjs npm expo child-process