[Workarounds] Packager unable to resolve module from /Users/node_modules/
Problem
There are various issues scattered around the repo related to this issue. Basically what happens is, for some packages, when you try to require `some-module` in a file, for example, [code block] It is unable to resolve the package and the following error appears, [code block] This error message is a symptom of the packager not being able to find `some-module`. It'll walk up the directory tree until it finds `node_modules/some-module`. It just so happens that `/Users` is the last directory to try, hence the weird `/Users/node_modules` directory in the error message (h/t @philikon). Workarounds Currently, the workarounds seem to be, - Delete the `node_modules` folder - `rm -rf node_modules && npm install` - Reset packager cache - `rm -fr $TMPDIR/react-*` or `node_modules/react-native/packager/packager.sh --reset-cache` - Clear watchman watches - `watchman watch-del-all` - Recreate the project from scratch
Error Output
error message is a symptom of the packager not being able to find `some-module`. It'll walk up the directory tree until it finds `node_modules/some-module`. It just so happens that `/Users` is the last dire
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: [Workarounds] Packager unable to resolve module from /Users/node_modules/
I suspect that this is actually an npm bug. It seems that npm is secretly deleting installed packages in my project's `node_modules` directory, when I install an unrelated package. When it blows up with an error, it references `/Users/node_modules/` because (I'm guessing) it's just searching up the directory tree 3-4 levels before giving up. re-running `npm install <module> —save` for each of t
Trust Score
7 verifications
- 1
I suspect that this is actually an npm bug. It seems that npm is secretly delet
I suspect that this is actually an npm bug. It seems that npm is secretly deleting installed packages in my project's `node_modules` directory, when I install an unrelated package. When it blows up with an error, it references `/Users/node_modules/` because (I'm guessing) it's just searching up the directory tree 3-4 levels before giving up.
- 2
re-running `npm install <module> —save` for each of the missing modules fixes th
re-running `npm install <module> —save` for each of the missing modules fixes this issue for me.
- 3
edit: My guess is that React Native's complex dependency structure is just expos
edit: My guess is that React Native's complex dependency structure is just exposing npm's bugs.
- 4
edit 2: Yeah, you pretty much want to blow away your project's `node_modules` di
edit 2: Yeah, you pretty much want to blow away your project's `node_modules` directory and do a fresh `npm install`. I think the issue is extra common if you depend on modules that React Native also depends on (say, lodash). `npm` just gets into a weird state with all the, ahem, flux :).
Validation
Resolved in facebook/react-native GitHub issue #4968. Community reactions: 44 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep