facebook / create-react-app

Set up a modern web app by running one command.
https://create-react-app.dev
MIT License
102.62k stars 26.79k forks source link

react-scripts start unhandled rejection handling makes missing dependencies painful to debug #10850

Open odama626 opened 3 years ago

odama626 commented 3 years ago
// react-scripts/scripts/start.js
//L15
// Makes the script crash on unhandled rejections instead of silently
// ignoring them. In the future, promise rejections that are not handled will
// terminate the Node.js process with a non-zero exit code.
process.on('unhandledRejection', err => {
  throw err;
});

when you're missing a dependency you get an error and a crash

/node_modules/react-scripts/scripts/start.js:19
  throw err;
  ^

[Error: ENOENT: no such file or directory, stat '/initrd.img'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'stat',
  path: '/initrd.img'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1

when you remove process.on('unhandledRejection', err => { throw err; }); it gives you a much more useful error and doesn't crash

Failed to compile.

./node_modules/[redacted]/dist/index.modern.js
Module not found: Can't resolve 'framer-motion' in '/home/[redacted]/node_modules/[redacted]/dist'

that small addition of code makes things much harder to debug when simply missing a peer dependency or something similar and could stop people dead in their tracks. maybe it should be removed until a better way of handling it can be thought of?

revelt commented 2 years ago

Since node v15, the --unhandled-rejections default is throw (source) so it seems this process.on('unhandledRejection', err => { is redundant; Node would throw nowadays (LTS is v16 currently).

The "In the future" time has came =)