Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does `nuxt generate` with @nuxt/pwa module generates always default icon in Gitlab-CI?

I have the following problem. I am using nuxt with the pwa module to generate a pre-rendered webpage. The @nuxt/pwa icon module should generate the different sized icons for the manifest.

This is also working when I run nuxt generate on my laptop.

In my gitlab-ci pipeline the generation also is working but it is always generating the default nuxt icon

https://d33wubrfki0l68.cloudfront.net/6ff34ec8760318b99888ee4b75d1e265170a84b9/6479c/logos/nuxt.svg

This icon I can not in my workspace so I guess it is somehow referenced in the docker build from node_modules.

I am using the following gitlab-ci job

build:
  image: node:alpine
  stage: build
  script:
    - npm run generate
  artifacts:
    paths:
      - dist/*
    expire_in: 14 days
  only:
    - master

The package.json looks like this:

  "scripts": {
    "generate": "nuxt generate",
    ...
  },
  "dependencies": {
    "@nuxtjs/pwa": "^3.0.0-beta.20",
    "nuxt": "^2.14.0",
    ...
  },
  "devDependencies": {
   ...
  }

I also tried a lot of different settings in my nuxt.conf.js as I guessed that the icon is not referenced correctly.

This was my last try

  pwa: {
    icon: {
      source: resolve(__dirname, './client/static/icon.png'),
    },
  },

But as it is found locally I thik that it is right.

Has anyone an idea why the nuxt generate does not work in gitlab-ci?

like image 556
thopaw Avatar asked Sep 19 '20 21:09

thopaw


People also ask

What is NUXT PWA?

The Nuxt. js PWA module registers a service worker for you to deal with offline caching. It automatically generates a manifest.json file. It automatically adds SEO friendly meta data with manifest integration. It automatically generates app icons with different sizes.

How do I use material icons in NUXT?

Step 1: Add Google fonts icon's CDN. Step 2: Use it (you are done!) Here is the complete list of Material Icons. Show activity on this post.

What is nuxt PWA?

⚡ Nuxt PWA. Progressive Web Apps (PWA) are reliable, fast, and engaging, although there are many things that can take a PWA from a baseline to exemplary experience.

What is ZeroZero config PWA solution for nuxt?

Zero config PWA solution for Nuxt.js Registers a service worker for offline caching. Automatically generate manifest.json file. Automatically adds SEO friendly meta data with manifest integration.

Why doesn't my nuxt have any icons?

The issue seems to be the old cache located at /node_modules/.cache/pwa/icon Nuxt doesn't generate new icons if the filenames are not changed so that is why the default icons are used. Especially if your new icon file is 'icon.png'.

How are routes generated in nuxt?

The generation of routes are concurrent, generate.concurrency specifies the amount of routes that run in one thread. As of Nuxt >= v2.13 Nuxt comes with a crawler installed that will crawl your relative links and generate your dynamic links based on these links.


3 Answers

The issue seems to be the old cache located at /node_modules/.cache/pwa/icon

Nuxt doesn't generate new icons if the filenames are not changed so that is why the default icons are used. Especially if your new icon file is 'icon.png'.

You could go about this three ways:

  1. Delete the cache at /node_modules/.cache/pwa/icon before deploying but this only works with local/dev environment so this is out.

  2. You could rename your file as the other comment suggested but you would have to rename it every time you change the file. So while this would work, it is still far from good, even for a hacky solution.

  3. The third approach would be to delete that folder in your yarn/npm generate script. This would look something like this:

generate: 'rm -r /node_modules/.cache/pwa/icon && nuxt generate';
like image 128
Surya Rajendhran Avatar answered Oct 23 '22 23:10

Surya Rajendhran


I had the same issue and the icons didn't get updated also on my local environment. For now I was able to fix it by adding

pwa: {
    icon: {
         fileName: 'app-icon.png',
    },
},

to my nuxt.config.js and change the filename accordingly. But thats probably a little hacky.

I use Netlify for deployment and cleared the cache there but with no luck. Did you cleared your Runner Cache in Gitlab and then tried again?

like image 26
Hermann Dettmann Avatar answered Oct 23 '22 22:10

Hermann Dettmann


This worked for me,

Delete the following:

  1. node_modules/.cache
  2. .nuxt
  3. dist(if generated)

Then do the following:

npm install
npm run generate
like image 3
Shashank Shekhar Barik Avatar answered Oct 23 '22 21:10

Shashank Shekhar Barik