Skip to content

[Packager] Command or flag to clean cache #1924

@brentvatne

Description

@brentvatne
Collaborator

When introducing a custom .babelrc, it's necessary to add the resetCache flag to the packager. This requires digging into node_modules and isn't the most developer friendly (DX anybody? :P)

So we should either allow users to do:

./node_modules/react-native/packager/packager.sh clean

or

./node_modules/react-native/packager/packager.sh -root . -clean

Also open to other solutions! cc @amasad

Activity

cyprusglobe

cyprusglobe commented on Jul 9, 2015

@cyprusglobe

+1

dozoisch

dozoisch commented on Jul 9, 2015

@dozoisch
Contributor

👍

shlomiatar

shlomiatar commented on Jul 9, 2015

@shlomiatar
Contributor

We use this quick and dirty gulp task:

gulp.task('clear-cache', function () {
  // Clear react-packager cache
  var tempDir = os.tmpdir();

  var cacheFiles = fs.readdirSync(tempDir).filter(function (fileName) {
    return fileName.indexOf('react-packager-cache') === 0;
  });

  cacheFiles.forEach(function (cacheFile) {
    var cacheFilePath = path.join(tempDir, cacheFile);
    fs.unlinkSync(cacheFilePath);
    console.log('Deleted cache: ', cacheFilePath);
  });

  if (!cacheFiles.length) {
    console.log('No cache files found!');
  }
});
brentvatne

brentvatne commented on Jul 10, 2015

@brentvatne
CollaboratorAuthor

Nice one @shlomiatar! Could you submit a pull request to add that command to the packager?

fabiomcosta

fabiomcosta commented on Jul 13, 2015

@fabiomcosta

+1

fabiomcosta

fabiomcosta commented on Jul 13, 2015

@fabiomcosta

ideally the cache key would consider the current babel transforms

zallek

zallek commented on Jul 28, 2015

@zallek

+1 thanks for the tip, and yeh a clean command would be appreciated :)

amasad

amasad commented on Sep 8, 2015

@amasad
Contributor

@martinbigio just shipped a diff that adds support for this. Should land soon.

gaearon

gaearon commented on Sep 17, 2015

@gaearon
Collaborator
hours_spent_here += 3;
alejomendoza

alejomendoza commented on Sep 19, 2015

@alejomendoza

👍 this is such an annoying bug 🪲 where do we add the gulp task?

shlomiatar

shlomiatar commented on Sep 20, 2015

@shlomiatar
Contributor

@alejomendoza,
You can install gulp by running npm install -g gulp.
then, you add gulpfile.js and add the task in it (and require the dependencies, os and fs)

you can run the task by typing gulp clear-cache on the same folder as the gulpfile.
good luck! :)

27 remaining items

j2kun

j2kun commented on Feb 27, 2017

@j2kun

@lprhodes This doesn't work for non-javascript file changes. What I have been doing (a really crappy workaround) is creating a watchman trigger for my specific file to run

find $TMPDIR/react-native-packager-cache-* -name "mypattern" | xargs rm

But this doesn't even work because I have to restart the packager for it to pick up that these cache files got deleted. I would really love a way to say "Hey packager, when this file changes, please re-transpile this other JS file!" But I've been searching and experimenting for a week and can't figure out how to do this.

j2kun

j2kun commented on Feb 27, 2017

@j2kun

This was the solution I was able to come up with. Would appreciate any suggestions for improvements, or better yet a principled way to do it

http://stackoverflow.com/questions/42212314/tell-react-native-packager-to-watch-a-non-javascript-file/42497592#42497592

david-a

david-a commented on Oct 9, 2017

@david-a

I had to remove both react-native-packager-cache-* (directory) AND haste-map-react-native-packager-* (file) from $TMPDIR
thank you all

tarheele

tarheele commented on Nov 18, 2017

@tarheele

On windows, I made the mistake of renaming node_modules to node_modules.todelete in an effort to debug an issue. Something cached this and gave me an error

P: error: bundling failed: ambiguous resolution: module [mymodule] tries to require 'react-native', but there are several files providing this module. You can delete or fix them:

  • ...\node_modules.todelete\react-native\package.json
  • ...\node_modules\react-native\package.json

The key for me was the haste removal tip by @david-a

I am sharing this mainly so folks can find the error text I encountered

leoskyrocker

leoskyrocker commented on Dec 27, 2017

@leoskyrocker

https://gist.github.com/jarretmoses/c2e4786fd342b3444f3bc6beff32098d#gistcomment-2277722

for RN50 the tmp cache files seems to have a different name
"clear": "rm -rf $TMPDIR/react-native-packager-cache-* && rm -rf $TMPDIR/metro-bundler-cache-*"

locked as resolved and limited conversation to collaborators on Jul 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @shlomiatar@fabiomcosta@nevir@janaka@brentvatne

        Issue actions

          [Packager] Command or flag to clean cache · Issue #1924 · facebook/react-native