Cached Custom NUXT Routes

Can you provide details as to what cache is cleared when using the ‘Clear Cache and redeploy site’? What are the differences between a build that is triggered from a commit to the repository vs a build hook or the ‘Retry Deploy’ button?

Our Setup
Front end is Nuxt js 2.x with target set to ‘static’ (SSG). We are generating some custom routes by calling a Drupal backend API via Axios in a custom module. This generation setup happens at build time using Nuxt’s ‘buildModules’ configuration, and is hooking into the Vue router with the ‘extendRoutes’ hook to inject the custom paths. We have disabled the generater’s crawler as we are explicitly defining all of the routes for the site (generate.crawler = false).
Site name: bcrf.netlify.app

Issue Details:
When new content (blog posts, products, etc) is created OR when existing content’s path is changed in the API, the new routes are not represented if the build is triggered via Build Hooks or the ‘Retry Deploy’ button in the Netlify Admin UI. The old routes (if changed) are present and appear to be served from cache while the new or changed routes return a 404 / Not Found. If a build is triggered from a commit to the Github repository or when selecting the ‘Clear Cache and redeploy site’ option in the Netlify UI, the new and changed routes work as expected. Content editors must be able to publish new content with new and changed routes via the build hooks triggered from the API without a commit to the repo or access to the Netlify UI.

We have tried

  • Adding route generation in ‘modules’ rather than ‘buildModules’.
  • Changing the sequence that the Nuxt modules are running (having route generation run first, etc).
  • Removing the ‘.nuxt’ build directory (where the Vue router is eventually compiled) from Nuxt’s ‘generate.cache.ignore’ list.
  • Clearing cache via appending “&& rm -rf …/cache” to build command as mentioned here: How to clear cache on branch deploy? - #2 by laura
    • Subsequent builds from Build Hooks succeeded without error, but did not have new / changed routes. Subsequent builds triggered from the ‘Clear Cache and redeploy site’ Netlify UI failed due to missing directories. Committing a change to the repository seemed to fix the build cache and get things back to normal.
  • Downloaded site files
    • New route directories do not exist
    • Only old routes exist. Altered routes do not.

Hey there!

Can you provide details as to what cache is cleared when using the ‘Clear Cache and redeploy site’?

What does "Clear cache and deploy site" do specifically? :wink:

What are the differences between a build that is triggered from a commit to the repository vs a build hook or the ‘Retry Deploy’ button?

Not a lot. We’ll build the files referenced in the commit SHA. So, for a re-deploy, that’ll be the last commit SHA. For a commit to the repo, we’ll likely get a later commit SHA.

The question I would be asking is – have the changes been made within the repo before the webhook is being called?

The build webhook is initiated from the Drupal CMS / API. When content editors update and add content, they manually trigger the build and deploy so that the static site generator can pull the new content and make it available as static content. This action is not associated with any changes to the repository.

When I added “&& rm -rf …/cache” to the build commend, the routes still appeared to be generated from cache and subsequent builds generated form the “Clear Cache and redeploy site” returned the following and the build failed

12:19:56 PM: buildbot version: 0966611527937161c7edcafc1347bc5a61d77108
12:19:57 PM: Building without cache
12:19:57 PM: Starting to prepare the repo for build
12:19:57 PM: No cached dependencies found. Cloning fresh repo
12:19:57 PM: git clone https://github.com/ENTERMEDIA/bcrf-ui
12:20:02 PM: Preparing Git Reference refs/heads/buildcache
12:20:05 PM: Parsing package.json dependencies
12:20:05 PM: Starting build script
12:20:06 PM: Installing dependencies
12:20:06 PM: Python version set to 2.7
12:20:07 PM: v12.18.0 is already installed.
12:20:07 PM: Now using node v12.18.0 (npm v6.14.4)
12:20:07 PM: Started restoring cached build plugins
12:20:07 PM: Finished restoring cached build plugins
12:20:07 PM: Attempting ruby version 2.7.1, read from environment
12:20:08 PM: Required ruby-2.7.1 is not installed - installing.
12:20:09 PM: Searching for binary rubies, this might take some time.
12:20:09 PM: Found remote file https://rvm_io.global.ssl.fastly.net/binaries/ubuntu/16.04/x86_64/ruby-2.7.1.tar.bz2
12:20:09 PM: Checking requirements for ubuntu.
12:20:10 PM: Requirements installation successful.
12:20:10 PM: ruby-2.7.1 - #configure
12:20:10 PM: ruby-2.7.1 - #download
12:20:11 PM: ruby-2.7.1 - #validate archive
12:20:15 PM: ruby-2.7.1 - #extract
12:20:18 PM: ruby-2.7.1 - #validate binary
12:20:19 PM: ruby-2.7.1 - #setup
12:20:19 PM: ruby-2.7.1 - #gemset created /opt/buildhome/.rvm/gems/ruby-2.7.1@global
12:20:20 PM: ruby-2.7.1 - #importing gemset /opt/buildhome/.rvm/gemsets/global.gems........................................
12:20:20 PM: ruby-2.7.1 - #generating global wrappers........
12:20:20 PM: ruby-2.7.1 - #gemset created /opt/buildhome/.rvm/gems/ruby-2.7.1
12:20:20 PM: ruby-2.7.1 - #importing gemsetfile /opt/buildhome/.rvm/gemsets/default.gems evaluated to empty gem list
12:20:21 PM: ruby-2.7.1 - #generating default wrappers........
12:20:21 PM: Using /opt/buildhome/.rvm/gems/ruby-2.7.1
12:20:22 PM: Using ruby version 2.7.1
12:20:22 PM: Using PHP version 5.6
12:20:22 PM: Started restoring cached node modules
12:20:22 PM: Finished restoring cached node modules
12:20:22 PM: Installing NPM modules using NPM version 6.14.4
12:20:52 PM: npm WARN tar ENOENT: no such file or directory, open '/opt/build/repo/node_modules/.staging/es-abstract-759047d7/2017/WeekDay.js'
12:20:52 PM: npm WARN tar ENOENT: no such file or directory, open '/opt/build/repo/node_modules/.staging/prismjs-18d2f6d8/themes/prism-twilight.css'
12:20:53 PM: npm WARN tar ENOENT: no such file or directory, open '/opt/build/repo/node_modules/.staging/es-abstract-759047d7/2018/WeekDay.js'
12:20:53 PM: npm WARN tar ENOENT: no such file or directory, open '/opt/build/repo/node_modules/.staging/source-map-6255b563/dist/source-map.min.js'
............
12:20:56 PM: npm WARN tar ENOENT: no such file or directory, open '/opt/build/repo/node_modules/.staging/rxjs-0d46fdac/_esm2015/internal/operators/takeUntil.js'
12:20:56 PM: npm WARN tar ENOENT: no such file or directory, open '/opt/build/repo/node_modules/.staging/rxjs-0d46fdac/_esm5/internal/operators/takeUntil.js'
12:20:57 PM: npm ERR! code E404
12:20:57 PM: npm ERR! 404 Not Found - GET https://registry.npmjs.org/@nuxtjs/style-resources/-/style-resources-1.2.1.tgz
12:20:57 PM: npm ERR! 404
12:20:57 PM: npm ERR! 404  '@nuxtjs/style-resources@1.2.1' is not in the npm registry.
12:20:57 PM: npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
12:20:57 PM: npm ERR! 404 It was specified as a dependency of 'repo'
12:20:57 PM: npm ERR! 404
12:20:57 PM: npm ERR! 404 Note that you can also install from a
12:20:57 PM: npm ERR! 404 tarball, folder, http url, or git url.

Is there a specific directory you can recommend we delete via the build command rather than …/cache that might replicate the functionality and delete the same directories that are deleted when using the ''Clear Cache and redeploy site" link and not break subsequent builds?

Hi @ENTERMEDIA,

Would it be possible for you to trigger a deploy using the API?

You need to make a POST request to https://api.netlify.com/api/v1/sites/<site-id>/builds with {"clear_cache":true} as the JSON body.

Can you provide an example of targeting a specific branch so we are not building the PROD site? We were able to trigger a build without cache using the API, but only targeting the production branch. Our content editors will need to deploy to a staging branch to stage and approve content prior to building production.

Does createSiteBuild accept anything in the payload that would allow us to target a specific context/branch? Netlify API documentation

I’m not aware of any such API call, but you could use the retry API. So you could trigger a push to your branch, cancel the build immediately, then retry by clearing cache. https://api.netlify.com/api/v1/deploys/<deploy id>/retry

I don’t think createSiteBuild could do what you’re trying.