【发布时间】:2018-09-17 15:55:34
【问题描述】:
如何在 ReactJS 应用程序中使用像“child_process”这样的模块?
(react@16.3.1 / Linux)
这些语法失败:
import { spawn } from 'child_process'
const ls = spawn('ls', ['-al']);
产量:TypeError: Object(...) is not a function
import cp from 'child_process';
const ls = cp.spawn('ls', ['-al']);
产量:TypeError: __WEBPACK_IMPORTED_MODULE_3_child_process___default.a.spawn is not a function
var { spawn } = require('child_process');
const ls = spawn('ls', ['-al']);
产量:TypeError: spawn is not a function
【问题讨论】:
-
你的用例到底是什么?
-
抱歉,我的问题表述不当:我的应用实际上有服务器端代码(发生异常的地方),但错误与 React 无关。我终于找到了导入模块 child_process.there 的方法。感谢您的帮助!
标签: javascript reactjs import require child-process