Create-react-native-app: npm run eject fails when removing node_modules

Created on 27 May 2018  路  6Comments  路  Source: expo/create-react-native-app

Description

When running npm run eject everything goes well up to the point where the code removes the node_modules folder where it fails on a random module.

Expected Behavior

The script runs without issues and displays a success message (or informs me in any way that everything went well.

Observed Behavior

Randomly while removing the process fails with the error message that a folder could not be removed because it is not empty. After that there is a line telling me that a directory was not found and then there is the usual npm error block:

Error running eject: Error: ENOTEMPTY: directory not empty, rmdir 'C:\Users\Username\ReactNative\ProjectName\node_modules\lottie-react-native\src\android\build\tmp\expandedArchives\classes.jar_5gdp4bb5izj6gs3qq6f6ejit7\com\facebook\react'
System cannot find the given directory (translated from German; might be inaccurate)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] eject: `react-native-scripts eject`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] eject script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Username\AppData\Roaming\npm-cache\_logs\2018-05-26T22_22_42_547Z-debug.log

I tried to get around this by using Ctrl+C to pause execution of the script, remove the folders in node_modules by hand and then continuing the process however that seemed to crash the script, no further output was printed and I was able to put in a new command (without yarn install for example was run).

Environment

Please run these commands in the project folder and fill in their results:

  • npm ls react-native-scripts:
[email protected] C:\Users\Username\ReactNative\ProjectName
`-- (empty)
(1.14.0 is installed)

  • npm ls react-native:
[email protected] C:\Users\Username\ReactNative\ProjectName
`-- UNMET DEPENDENCY [email protected]

npm ERR! missing: [email protected], required by [email protected]
npm ERR! extraneous: [email protected] C:\Users\Username\ReactNative\ProjectName\node_modules\react-native

(0.55.4 is installed)

  • npm ls expo:
[email protected] C:\Users\Username\ReactNative\ProjectName
`-- UNMET DEPENDENCY [email protected]

npm ERR! missing: [email protected], required by [email protected]

(27.0.1 is installed)

  • node -v: v8.9.1
  • npm -v: 6.0.0
  • yarn --version: 1.6.0
  • watchman version: 4.9.1

Also specify:

  1. Operating system: Windows 7 64-bit
  2. Phone/emulator/simulator & version: iPhone 5S, Galaxy S5

Reproducible Demo

Create a new project, change into the directory and eject
create-react-native-app TestingNodeModulesRemoval && cd TestingNodeModuleRemoval && npm run eject

However the issue can already be seen without ejecting by just trying to remove the node_modules folder with the command rmdir /S /Q node_modules. This is also described in this stackoverflow post and appears to be a windows issue. It would be great though if some kind of workaround could be implemented so this does not randomly happen.

Running the command from an administrator prompt did not solve the issue.

Most helpful comment

my solution: npm install -g react-native-scripts then run react-native-scripts eject . this will do the same as npm run eject. hope it works!

All 6 comments

Workaround: Run the command from git bash if installed. That completed the removal of node_modules without error. This might work with the WSL as well but I haven't tested that.
If there is a solution for the windows command line though, it would be much appreciated if someone could post this here :)

FYI, you actually have to add everything to git before running npm run eject. This resolved node_modules removal issue for me.

When I was testing with a small project I did not use git in that directory at all, so I doubt that was the cause (you don't need to git init in order to reproduce the problem).

Yeah, me too, but when I've initialized git and added everything - the error was gone while deleting node_modules.
It didn't help running whole npm run eject script successfully tho :/

Strange. I tried the same thing but it wouldn't work either. Anyway; using git bash instead of the windows command-line appears to get rid of that issue.

my solution: npm install -g react-native-scripts then run react-native-scripts eject . this will do the same as npm run eject. hope it works!

Was this page helpful?
0 / 5 - 0 ratings