![](/img/trans.png)
[英]Module not found: Can't resolve 'child_process' while using Electron React Boilerplate
[英]InternalError Metro has encountered an error: While trying to resolve module `child_process`
我正在尝试从 js 文件调用 python 文件中的 function ,我通过我的控制台让它工作,但我现在正尝试使用 Z44CA7EFD814E428097ZAF4D5E75B1CDF5 在移动应用程序中实现它
我设置的方式是,我的应用程序中有某个屏幕的 JS 文件,然后在单独的 JS 文件中调用 function,然后在 Z23EEEB4347BDD7526BFC6B7EEA9 中调用 function。
我正在使用child_process
模块从 JS 与 python 交谈。
正如我所说,在我尝试将 JS function 导出到我的屏幕文件之前,这是可行的。
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:
我怎样才能解决这个问题?
由于几个原因它不起作用
child_process
是 node 标准库的一部分,在 react-native 或浏览器等其他环境中不可用python.py
文件甚至不会上传到手机,因为捆绑程序只上传一个包含整个 js 代码组合 + 资产的大 js 文件, python.py
两者都不是。只有将该代码重写为 javascript 才有意义的解决方案。
从技术上讲这不是不可能的,可能有办法做到这一点,通过为移动平台编译 python 解释器,或者使用一些将 python 代码翻译成 js 的工具,但这不是你应该考虑的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.