admin管理员组文章数量:1310532
How does one use a module like 'child_process' from a ReactJS app?
([email protected] / Linux)
These syntaxes fail:
import { spawn } from 'child_process'
const ls = spawn('ls', ['-al']);
yields: TypeError: Object(...) is not a function
import cp from 'child_process';
const ls = cp.spawn('ls', ['-al']);
yields: TypeError: __WEBPACK_IMPORTED_MODULE_3_child_process___default.a.spawn is not a function
var { spawn } = require('child_process');
const ls = spawn('ls', ['-al']);
yields: TypeError: spawn is not a function
How does one use a module like 'child_process' from a ReactJS app?
([email protected] / Linux)
These syntaxes fail:
import { spawn } from 'child_process'
const ls = spawn('ls', ['-al']);
yields: TypeError: Object(...) is not a function
import cp from 'child_process';
const ls = cp.spawn('ls', ['-al']);
yields: TypeError: __WEBPACK_IMPORTED_MODULE_3_child_process___default.a.spawn is not a function
var { spawn } = require('child_process');
const ls = spawn('ls', ['-al']);
yields: TypeError: spawn is not a function
- What's your use case exactly ? – Bmaed Riasbet Commented Apr 7, 2018 at 23:16
- Sorry my question was poorly formulated: my app actually has server-side code (where the exception happens) but the error had nothing to do with React. I finally found a way to import module child_process.there. Thanks for your help! – Francois Commented Apr 18, 2018 at 7:26
2 Answers
Reset to default 4You can't use node's module child_process
in a react application.
You can't access to OS system processes to spawn and fork from browser because it's an isolated environment.
ReactJS is only working on the client side of you app and interacting with the DOM. Child processes are fired on the server side of your app.
So those two thing are separated.
ReactJS could make an http call for example to the server that will then trigger the child process. The server could send the results of the child process back to the React client.
本文标签: javascripthow to import module 39childprocess39 on server side of a ReactJS appStack Overflow
版权声明:本文标题:javascript - how to import module 'child_process' on server side of a ReactJS app - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741800825a2398211.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论