vite-pwa / astro

Zero-config PWA Integration for Astro
https://vite-pwa-org.netlify.app/frameworks/astro
MIT License
195 stars 7 forks source link

Uncaught ReferenceError: _page4 is not defined at bundledWorker-0.8194009624159182.mjs:2149:38 #45

Closed zanhk closed 6 months ago

zanhk commented 6 months ago

Not sure what I am missing but when I build the the project on the file

_worker.js/index.js

there is a missing declaration of _page4 and _page6 which are later used on pageMap

const _page0 = () => import('./chunks/image-endpoint_RvDj3-CK.mjs');
const _page1 = () => import('./chunks/keystatic-api_Bfk-cUm8.mjs');
const _page2 = () => import('./chunks/keystatic-astro-page_DIVZxRMu.mjs');
const pageMap = new Map([
    ["node_modules/@astrojs/cloudflare/dist/entrypoints/image-endpoint.js", _page0],
    ["node_modules/@keystatic/astro/internal/keystatic-api.js", _page1],
    ["node_modules/@keystatic/astro/internal/keystatic-astro-page.astro", _page2],

    ["src/pages/post/[...slug].astro", _page4],

    ["src/pages/[...slug].astro", _page6]
]);

Full build log:

E:\repositories\majestico\antares>bun run build
$ astro build
10:12:49 [WARN] The currently selected adapter `@astrojs/cloudflare` is not compatible with the image service "Sharp".
10:12:50 [build] output: "hybrid"
10:12:50 [build] directory: E:\repositories\majestico\antares\dist\
10:12:50 [build] adapter: @astrojs/cloudflare
10:12:50 [build] Collecting build info...
10:12:50 [build] ✓ Completed in 639ms.
10:12:50 [build] Building hybrid entrypoints...
10:12:53 [astro-icon] Loaded icons from src/icons, ic, mdi, solar
Generated an empty chunk: "pages/image-endpoint.js".
10:12:59 [vite] ✓ built in 8.70s
10:12:59 [build] ✓ Completed in 8.74s.

 building client (vite) 
10:13:04 [vite] ✓ 1183 modules transformed.
Generated an empty chunk: "hoisted".
10:13:06 [vite] dist/manifest.webmanifest                                                      0.45 kB
10:13:06 [vite] dist/_astro/Highlights.astro_astro_type_script_index_0_lang.BaCW6DQl.js        0.30 kB │ gzip:   0.23 kB
10:13:06 [vite] dist/_astro/hoisted.B_gY8znj.js                                                0.47 kB │ gzip:   0.29 kB
10:13:06 [vite] dist/_astro/Testimonials.astro_astro_type_script_index_0_lang.CL6AE6rR.js      0.69 kB │ gzip:   0.31 kB
10:13:06 [vite] dist/_astro/client.DWoRQa5Q.js                                                 1.56 kB │ gzip:   0.81 kB
10:13:06 [vite] dist/_astro/workbox-window.prod.es5.DFjpnwFp.js                                5.29 kB │ gzip:   2.19 kB
10:13:06 [vite] dist/_astro/hoisted.Bd2Fo4VE.js                                               14.96 kB │ gzip:   5.41 kB
10:13:06 [vite] dist/_astro/Hero.astro_astro_type_script_index_0_lang.r2T_yKjW.js             16.50 kB │ gzip:   5.72 kB
10:13:06 [vite] dist/_astro/ScrollTrigger.BS49OFpx.js                                         42.88 kB │ gzip:  17.91 kB
10:13:06 [vite] dist/_astro/page.BIe0mclZ.js                                                  43.67 kB │ gzip:  15.77 kB
10:13:06 [vite] dist/_astro/index.ZORhgBxb.js                                                 69.87 kB │ gzip:  27.65 kB
10:13:06 [vite] dist/_astro/index.ClJOJl_Y.js                                                141.89 kB │ gzip:  45.63 kB
10:13:06 [vite] dist/_astro/keystatic-page.DeFKh_T3.js                                     2,501.72 kB │ gzip: 774.46 kB
10:13:06 [WARN] [vite]
(!) Some chunks are larger than 500 kB after minification. Consider:
- Using dynamic import() to code-split the application
- Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/configuration-options/#output-manualchunks
- Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
10:13:06 [vite] ✓ built in 6.93s

PWA v0.19.8
mode      generateSW
precache  34 entries (3847.74 KiB)
files generated
  dist/sw.js
  dist/workbox-7cfec069.js

 prerendering static routes 
10:13:08 ▶ src/pages/404.astro
10:13:08   └─ /404.html (+20ms)
10:13:08 ▶ src/pages/post/[...slug].astro
10:13:08 λ src/pages/rss.xml.js
10:13:08   └─ /rss.xml10:13:08 [WARN] [router] No API Route handler exists for the method "GET" for the route "/rss.xml".
Found handlers: "get"

 (+1ms)
10:13:08 ▶ src/pages/[...slug].astro
10:13:08   ├─ /index.html (+40ms)
10:13:08   └─ /prenota/index.html (+6ms)
10:13:08 ✓ Completed in 351ms.

 generating optimized images 
10:13:08   ▶ /_astro/background.x7SdbNqx_Z1tR8KA.webp (reused cache entry) (+1ms) (1/7)
10:13:08   ▶ /_astro/cover.Ctfop-R5_Z3JMed.webp (reused cache entry) (+0ms) (2/7)
10:13:08   ▶ /_astro/shutterstock_2285143617.CvtnyURn_ZRKDpv.webp (reused cache entry) (+0ms) (3/7)
10:13:08   ▶ /_astro/shutterstock_2182538863.DEKqqcdz_2hfRr9.webp (reused cache entry) (+0ms) (4/7)
10:13:08   ▶ /_astro/orthodontics.C1llijSB_nlLNI.webp (reused cache entry) (+0ms) (5/7)
10:13:08   ▶ /_astro/checkup.GXJZ2ypV_ZLYrav.webp (reused cache entry) (+0ms) (6/7)
10:13:08   ▶ /_astro/cover.Cw7VWPk8_Z1RxFs9.webp (reused cache entry) (+0ms) (7/7)
10:13:08 ✓ Completed in 7ms.

10:13:08 
 finalizing server assets 

10:13:08 [build] Rearranging server assets...
10:13:08 [@astrojs/sitemap] `sitemap-index.xml` created at `dist`

PWA v0.19.8
mode      generateSW
precache  39 entries (4070.33 KiB)
files generated
  dist/sw.js
  dist/workbox-7cfec069.js
10:13:09 [build] Server built in 19.45s
10:13:09 [build] Complete!

My configuration:

import alpinejs from "@astrojs/alpinejs";
import cloudflare from "@astrojs/cloudflare";
import markdoc from "@astrojs/markdoc";
import react from "@astrojs/react";
import sitemap from "@astrojs/sitemap";
import tailwind from "@astrojs/tailwind";
import keystatic from "@keystatic/astro";
import AstroPWA from "@vite-pwa/astro";
import icon from "astro-icon";
import { defineConfig } from "astro/config";

// https://astro.build/config
export default defineConfig({
    site: "https://antares.majestico.it",
    output: "hybrid",
    adapter: cloudflare({
        imageService: "compile",
    }),
    markdown: {
        drafts: true,
        shikiConfig: {
            theme: "css-variables",
        },
    },
    i18n: {
        defaultLocale: "it",
        locales: ["en", "it"],
    },
    shikiConfig: {
        wrap: true,
        skipInline: false,
        drafts: true,
    },
    redirects: {
        "/admin": "/keystatic",
    },
    vite: {
        define: {
            __DATE__: `'${new Date().toISOString()}'`,
        },
    },
    integrations: [
        alpinejs(),
        tailwind({
            // Base style is applied on the file global.css
            applyBaseStyles: false,
        }),
        sitemap(),
        icon(),
        react(),
        markdoc(),
        keystatic(),
        AstroPWA({
            mode: import.meta.env.PROD ? "production" : "development",
            base: "/",
            scope: "/",
            includeAssets: ["favicon.svg"],
            registerType: "autoUpdate",
            injectRegister: false,
            manifest: {
                name: "Astro PWA",
                short_name: "Astro PWA",
                theme_color: "#ffffff",
            },
            pwaAssets: {
                config: true,
            },
            workbox: {
                navigateFallback: "/",
                globPatterns: ["**/*.{css,js,html,svg,png,ico,txt}"],
                navigateFallbackDenylist: [/^\/keystatic/, /^\/api/],
                skipWaiting: true,
                maximumFileSizeToCacheInBytes: 3 * 1024 * 1024,
            },
            devOptions: {
                enabled: false,
                navigateFallbackAllowlist: [/^\//],
            },
            experimental: {
                directoryAndTrailingSlashHandler: true,
            },
        }),
    ],
});

output is hybrid but both slugs (pages/[...slug].astro and pages/post/[...slug].astro) are statically built.

import { registerSW } from "virtual:pwa-register";

registerSW({
    immediate: true,
    onRegisteredSW(swScriptUrl) {
        // eslint-disable-next-line no-console
        console.log("SW registered: ", swScriptUrl);
    },
    onOfflineReady() {
        // eslint-disable-next-line no-console
        console.log("PWA application ready to work offline");
    },
});
{
    "name": "@majesticostudio/altair",
    "type": "module",
    "version": "0.0.1",
    "private": true,
    "repository": {
        "type": "git",
        "url": "https://github.com/majesticostudio/altair.git"
    },
    "bugs": "https://github.com/majesticostudio/altair/issues",
    "homepage": "https://github.com/majesticostudio/altair",
    "scripts": {
        "dev": "astro dev",
        "start": "astro dev",
        "build": "astro build",
        "preview": "astro preview",
        "astro": "astro",
        "wrangler:dev": "wrangler pages dev",
        "pwa:generate-assets": "pwa-assets-generator --preset minimal public/logo.svg"
    },
    "dependencies": {
        "@astrojs/alpinejs": "^0.4.0",
        "@astrojs/cloudflare": "^10.2.0",
        "@astrojs/markdoc": "^0.10.0",
        "@astrojs/react": "^3.3.0",
        "@astrojs/rss": "^4.0.5",
        "@astrojs/sitemap": "^3.1.4",
        "@astrojs/tailwind": "^5.1.0",
        "@cloudflare/pages-plugin-mailchannels": "^0.1.3",
        "@keystatic/astro": "^5.0.0",
        "@keystatic/core": "^0.5.11",
        "alpinejs": "^3.13.8",
        "astro": "^4.6.3",
        "gsap": "npm:@gsap/business@^3.12.5",
        "react": "^18.2.0",
        "react-dom": "^18.2.0"
    },
    "devDependencies": {
        "@astrolib/seo": "1.0.0-beta.5",
        "@biomejs/biome": "1.7.0",
        "@cloudflare/workers-types": "^4.20240419.0",
        "@iconify-json/ic": "^1.1.17",
        "@iconify-json/mdi": "^1.1.66",
        "@iconify-json/solar": "^1.1.9",
        "@tailwindcss/aspect-ratio": "^0.4.2",
        "@tailwindcss/forms": "^0.5.7",
        "@tailwindcss/typography": "^0.5.12",
        "@types/alpinejs": "^3.13.10",
        "@types/react": "^18.2.79",
        "@types/react-dom": "^18.2.25",
        "@vite-pwa/assets-generator": "^0.2.4",
        "@vite-pwa/astro": "^0.3.1",
        "astro-icon": "^1.1.0",
        "tailwindcss": "^3.4.3",
        "workbox-window": "^7.0.0",
        "sharp": "0.33.3"
    },
    "overrides": {
        "gsap": "npm:@gsap/business@^3.12.5",
        "sharp": "0.33.3"
    }
}

I m using view transitions and all packages are updated to the latest version.

What am I missing?

Thanks

zanhk commented 6 months ago

The problem seem to be the package "@astrojs/cloudflare": "^10.2.0",

with "^10.1.0", works, with "^10.2.0" it don't: https://github.com/withastro/adapters/issues/237

zanhk commented 6 months ago

Closing as it's a bug on https://github.com/withastro/adapters/issues/237