Skip to content

[Workarounds] Packager unable to resolve module from /Users/node_modules/ #4968

Closed
@satya164

Description

@satya164
Contributor

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,

var someModule = require('some-module');

It is unable to resolve the package and the following error appears,

Unable to resolve module some-module from /Users/username/projectname/AwesomeProject/index.js: Invalid directory /Users/node_modules/some-module

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

Activity

brentvatne

brentvatne commented on Dec 24, 2015

@brentvatne
Collaborator
amasad

amasad commented on Dec 25, 2015

@amasad
Contributor
amasad

amasad commented on Dec 25, 2015

@amasad
Contributor

That's really strange. Next time it happens can you list your watch roots? watchman watch-list

hufeng

hufeng commented on Dec 25, 2015

@hufeng
martinbigio

martinbigio commented on Dec 25, 2015

@martinbigio
Contributor

Do we have a consistent repro case? I've experienced this too.

Hybrid-Force

Hybrid-Force commented on Dec 25, 2015

@Hybrid-Force

Same problem here on version 0.17.0.

$ watchman watch-list
{
    "version": "3.8.0",
    "roots": []
}
arypurnomoz

arypurnomoz commented on Dec 25, 2015

@arypurnomoz

I also got this problem when requesting for platform=ios

udnisap

udnisap commented on Dec 25, 2015

@udnisap
Contributor

Do we have a way to recreate this? Any steps that might recreate.

sgonyea

sgonyea commented on Dec 25, 2015

@sgonyea

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 the missing modules fixes this issue for me.

edit: My guess is that React Native's complex dependency structure is just exposing npm's bugs.

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 :).

720 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugHelp Wanted :octocat:Issues ideal for external contributors.JavaScriptResolution: LockedThis issue was locked by the bot.Tech: Bundler 📦This issue is related to the bundler (Metro, Haul, etc) used.📮Known IssuesThis indicates an issue that refers to a bug or limitation of RN that is not currently being handled

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @mmmurf@helozjisky@0x6e6562@diegochavez@ignu

      Issue actions

        [Workarounds] Packager unable to resolve module from /Users/node_modules/ · Issue #4968 · facebook/react-native