shadowwalker / next-pwa

Zero config PWA plugin for Next.js, with workbox 🧰
MIT License
3.75k stars 311 forks source link

bad-precaching-response :: [{"url":"_next/server/font-loader-manifest.js","status":500}] #437

Open mikloshumli opened 1 year ago

mikloshumli commented 1 year ago

Summary

Production page bad-precaching-response :: [{"url":"_next/server/font-loader-manifest.js","status":500}]

Versions

Screenshots

Screenshot 2022-12-09 at 19 03 28

next.config.js

const runtimeCaching = require('next-pwa/cache');
const withPlugins = require('next-compose-plugins');
const { withSentryConfig } = require('@sentry/nextjs');

/**
 * @type {import('@next/bundle-analyzer')}
 */
const withBundleAnalyzer = require('@next/bundle-analyzer')({
  enabled: process.env.ANALYZE === 'true',
  openAnalyzer: true
});

/**
 * @type {import('next-pwa').arguments}
 */
const withPWA = require('next-pwa')({
  runtimeCaching,
  dest: 'public',
  register: true,
  sw: 'service-worker.js',
  skipWaiting: true,
  cacheOnFrontEndNav: true,
  reloadOnOnline: true,
  buildExcludes: [/_middleware\.js\.map$/, /chunks\/images\/.*$/, /chunks\/pages\/api\/.*/],
  exclude: [/\.map$/, /^.*ts.*$/, /-manifest.json$/],
  publicExcludes: ['!robots.txt', '!noprecache/**/*'],
  sourcemap: false,
  maximumFileSizeToCacheInBytes: 10485760, // 10mb
  disable: process.env.NODE_ENV === 'development'
});

const SentryWebpackPluginOptions = {
  // Additional config options for the Sentry Webpack plugin. Keep in mind that
  // the following options are set automatically, and overriding them is not
  // recommended:
  //   release, url, org, project, authToken, configFile, stripPrefix,
  //   urlPrefix, include, ignore
  // For all available options, see:
  // https://github.com/getsentry/sentry-webpack-plugin#options.
  silent: true
};

/**
 * @type {import('next').NextConfig}
 */
const nextConfig = {
  compiler: {
    removeConsole: process.env.NODE_ENV !== 'development'
  },
  productionBrowserSourceMaps: false,
  experimental: {
    isrMemoryCacheSize: 0
  },
  sentry: {
    widenClientFileUpload: true,
    hideSourceMaps: true
  },
  images: {
    domains: [
      'placeholder.com',
      'via.placeholder.com',
    ],
    minimumCacheTTL: 60,
    formats: ['image/webp'],
    dangerouslyAllowSVG: true,
    contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;"
  },
  styledComponents: false,
  reactStrictMode: true,
  eslint: {
    ignoreDuringBuilds: true
  },
  webpack(config, { webpack }) {
    config.plugins.push(
      new webpack.DefinePlugin({
        __SENTRY_DEBUG__: false,
        __SENTRY_TRACING__: false
      })
    );
    config.module.rules.push({
      test: /\.svg$/,
      use: [
        {
          loader: '@svgr/webpack',
          options: {
            icon: true,
            prettier: false,
            svgo: true,
            titleProp: true
          }
        }
      ]
    });
    return config;
  },
  async rewrites() {
    return {
      afterFiles: [
      ],
      fallback: [
        {
          source: '/:path*',
          destination: '/404/:path*'
        }
      ]
    };
  }
};

const nextPlugins = [withBundleAnalyzer, withPWA];

module.exports = withSentryConfig(withPlugins(nextPlugins, nextConfig), SentryWebpackPluginOptions);
shadowwalker commented 1 year ago

_next/server/font-loader-manifest.js server side generated files should already be excluded. Not sure why you are getting this error. https://github.com/shadowwalker/next-pwa/blob/1e6af5fa9f6a807930f451adb5ab5078d5cda451/index.js#L216