Next.js 13.4.1 & Webpack 5.89.0: Not Generating Source Maps for Chunks in Production

43 views Asked by At

I'm working on a Next.js project (version 13.4.1) with Webpack (version 5.89.0) and encountering an issue where source maps are not being generated for my JavaScript chunk files in the production build. This issue is significantly impacting my ability to debug production-specific issues.

Here's a brief overview of my setup and what I've tried so far:

Issue: In my production build, .map files are missing for all chunks/*.js files, despite configuring my next.config.js to enable source map generation for production builds. Interestingly, source maps are generated for other files (e.g., .next/server/...), but the chunk files are notably absent.

Configuration (next.config.js):

const nextConfig = {
 ...
  productionBrowserSourceMaps: true,
  webpack(webpackConfig, { isServer }) {
    if (!isServer) {
        webpackConfig.devtool = 'source-map';
      
        // Optionally, customize the filenames of the source maps
        webpackConfig.output = {
         ...webpackConfig.output,
             // Ensure chunk files also have source maps
         sourceMapFilename: '[file].map',
        };
      
        // For debugging, log the Webpack config to verify changes
        console.log(config);
      }
  },
};
module.exports = nextConfig;

on post build, checking for the map files gives this:

$ find .next -type f -name "*.map"
.next/server/edge-runtime-webpack.js.map
.next/server/src/middleware.js.map
.next/static/css/e246aa7cf79af19a.css.map

Attempts to Resolve:

  • Explicitly setting devtool to 'source-map' in next.config.js.
  • Ensuring no conditional configurations might be preventing source map generation for chunk files.
  • Conducting clean builds to preclude any caching issues from affecting the generation process.
  • Searching through Next.js documentation and community forums without finding a resolution.

Questions:

  • Are there known issues with source map generation in Next.js 13.4.1 or Webpack 5.89.0 that might cause this behavior?
  • Could there be additional configuration steps or settings I've overlooked that are specific to chunk file source map generation?
  • Any suggestions on how to further diagnose or troubleshoot this issue within Next.js?
0

There are 0 answers