2

I'm trying to run the example from an npm package that uses parcel.

The example uses a url that makes an api call.

To run the example I do: npm test

Below are the 2 attempts that I made to stop the caching. I modify the index.js, kill the local server and restart and it caches no matter what. I'm just looking to run the example and make changes and see the results. It is obviously using the dist folder, but I keep deleting things, but the issue still persists. Any suggestions would be appreciated. Feel free to ask why would I ever want to do this.

package.json

"scripts": {
    "test": "parcel example/index.html --no-cache",
    "patch": "npm version patch --no-git-tag-version",
    "minor": "npm version minor --no-git-tag-version",
    "major": "npm version major --no-git-tag-version"
}
BenM
  • 52,573
  • 26
  • 113
  • 168
zakariah1
  • 362
  • 1
  • 11

3 Answers3

3

It seems that although --no-cache technically does disable Parcel's aggressive caching, in practice it requires a few more awkward steps to actually see any new changes you've made.

In addition to running parcel with the --no-cache option, you also need to close or completely kill the terminals running any current instances of the parcel local server, and also need to bypass the browser cache by doing a hard refresh (CtrlShiftR in Firefox).

Hashim Aziz
  • 4,074
  • 5
  • 38
  • 68
1

I ran into a similar problem and thus use the following scripts in package.json to ensure that I have no leftovers from previous builds. Unfortunately, this does still require rerunning the npm run dev command whenever I want to have a clean setup:

  "scripts": {
    "build": "rm -rf dist .parcel-cache && parcel build src/index.html",
    "dev": "rm -rf dist-dev .parcel-cache && parcel --dist-dir dist-dev src/index.html"
  }
Florian Feldhaus
  • 5,567
  • 2
  • 38
  • 46
-1

The docs for the --no-cache flag say:

Caching can also be disabled using the --no-cache flag. Note that this only disables reading from the cache – a .parcel-cache folder will still be created.

So my hunch is that it's working as expected. In most contexts it's totally fine to allow parcel to create a .parcel-cache folder (although it's best practice to add this folder to .gitignore). Is there something about your context that makes this a problem?

Andrew Stegmaier
  • 3,429
  • 2
  • 14
  • 26
  • All this answer does is reference the docs about the `.parcel-cache` folder, but the question was about the `--no-cache` flag not working and made absolutely no reference to `.parcel-cache`. – Hashim Aziz Jun 12 '22 at 22:24
  • The question is about disabling parcel's caching using the --no-cache flag, and the .parcel-cache folder _is_ that cache on disk. – Andrew Stegmaier Jun 13 '22 at 17:38
  • I'm aware, the point is that the user didn't complain about the folder being created, but that caching is still happening when using `--no-cache` - therefore, references to the folder are essentially irrelevant for the purposes of their question. – Hashim Aziz Jun 13 '22 at 17:42
  • BenM didn't clarify exactly why he thought parcel was still using the cache, but one reason why someone might think that --no-cache flag wasn't being respected is that the .parcel-cache folder gets created anyways (which, to be fair, is a little bit confusing). – Andrew Stegmaier Jun 13 '22 at 19:05