react-native-clean-project: Command 'wipe node_modules' failed with code: 1

When I run the command npx react-native clean-project-auto I get the following error and the process terminates.

Error running 'wipe node_modules': rm: 
Error running 'wipe node_modules': fts_read
Error running 'wipe node_modules': : 
Error running 'wipe node_modules': No such file or directory

❌  Command 'wipe node_modules' failed with code: 1
/Users/sushrut/Documents/GitHub/Desora-Smoker-RN/node_modules/@react-native-community/cli/build/index.js:99
    const message = err.message.replace(/\.$/, '');
                        ^

TypeError: Cannot read property 'message' of undefined
    at handleError (/Users/sushrut/Documents/GitHub/Desora-Smoker-RN/node_modules/@react-native-community/cli/build/index.js:99:25)
    at Command.handleAction (/Users/sushrut/Documents/GitHub/Desora-Smoker-RN/node_modules/@react-native-community/cli/build/index.js:189:7)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Library Version: 3.6.4 OS: macOS Big Sur 11.5.2

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 3
  • Comments: 41 (18 by maintainers)

Most upvoted comments

Just to give an update - I’ve been working on this fix (although I can’t seem to replicate it). Progress is happening (despite being slightly slow).

@pmadruga, I believe this is a concurrency problem. It seems like executeTask is returning a promise, but on index.js we’re not waiting promise to resolve/reject.

if (options.getWipeiOSBuild()) {
  executeTask(tasks.wipeiOSBuildFolder);
}
if (options.getWipeiOSPods()) {
  executeTask(tasks.wipeiOSPodsFolder);
}
if (options.getWipeSystemiOSPodsCache()) {
  executeTask(tasks.wipeSystemiOSPodsCache);
}

In other words, we’re trying to execute these tasks at the same time without knowing which one will be resolved/rejected first. This is causing node_modules to be removed before tasks.cleanAndroidProject which is probably throwing the above.

If I execute the process with flag --keep-node-modules, everything works fine on my end.

@roryabraham I can see that the alpha version solves this issue for you - can you confirm?

Yes! After upgrading to ^4.0.0-alpha4.0 I haven’t had any issues.

Firstly, thank you for the great debug session - it really helps in tackling this.

Yes, I have the same gut feeling. From reading the code, I doubt that it’s truly asynchronous. So in the next few days, I’m going to rewrite it and hopefully, alpha3 will have it fixed.

I’ll write here as soon as alpha3 is released.

I got the same error. node_modules is not empty before, but after running the command and getting this error, node_modules/.bin is gone, so no commands will work anymore, e.g npx react-native clean-project will fail after that due to the react-native command no longer being found. Need to run rm -rf node_modules && yarn to get it back