Closed Coord closed 6 years ago
Hi Coord,
I am having the exact same issue. What code changes did you make to run the demo? After I simply switch to "exec" from "spawn" and define "exec", it still fails. Appreciate if you could shed more light.
const exec = require('child_process').exec;
const client = exec('./node_modules/.bin/react-scripts', ['start'], {
env: Object.assign({}, process.env, {
REACT_APP_SERVER: 'http://localhost:5000',
}),
stdio: 'inherit',
});
Thanks Lee
Hi Lee,
Here is my updated start.js file:
const exec = require('child_process').exec;
const server = require('../server');
const client = exec(__dirname + '/../node_modules/.bin/react-scripts start', {
env: Object.assign({}, process.env, {
REACT_APP_SERVER: 'http://localhost:5000',
})
}, (error, stdout, stderr) => {
if (error) {
// eslint-disable-next-line no-console
console.log(`ERROR: ${error}`);
killServer(() => {
process.exit(1);
});
return;
}
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
});
function killServer(callback) {
const ppid = server.pid;
const killer = exec('pkill -9 -P ' + ppid);
killer.on('exit', () => {
// eslint-disable-next-line no-console
console.log(`PPID ${ppid} killed`);
if (callback) {
callback();
}
});
}
I also had to change one of the script commands in package.json to make it work correctly:
"build": "./node_modules/.bin/react-scripts build"
I did these changes relatively quickly, so it may be a little hacky. Let me know if you find a better solution :)
Thank you, Coord,
@maniax89 do you think you can take a look at this? @Coord sent me an email and I think this is one of the changes your team did to adopt create-react-app
I have made a fix in #91 and it should work cross-platform now (sorry about that)
as for appending the ./node_modules/.bin
-> I have removed this from all code as any script run with npm run
supposedly adds the ./node_modules/.bin
to the $PATH
, thus we should never need to include it in scripts.
Let us know if you still have issues
:tada: This issue has been resolved in version 1.0.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
Error from logs:
Server running on port: 5000 ERROR: Error: spawn ./node_modules/.bin/react-scripts ENOENT events.js:160 throw er; // Unhandled 'error' event ^
Error: spawn pkill ENOENT at exports._errnoException (util.js:1018:11) at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32) at onErrorNT (internal/child_process.js:367:16) at _combinedTickCallback (internal/process/next_tick.js:80:11) at process._tickCallback (internal/process/next_tick.js:104:9) at Module.runMain (module.js:606:11) at run (bootstrap_node.js:390:7) at startup (bootstrap_node.js:150:9) at bootstrap_node.js:505:3
After debugging for a long time, I eventually had to modify scripts/start.js to use 'exec' instead of 'spawn' to make it work. Here is the page that talks about the issue with spawn on Windows machines and cross-platform executions:
https://nodejs.org/api/child_process.html#child_process_spawning_bat_and_cmd_files_on_windows
Please let me know if you happen to know a better way to solve this issue. Thanks.