首页 > 解决方案 > 如何为 nextjs 生成源图?

问题描述

我正在为我的应用程序使用 Next.js,并且我想生成源映射来检查包大小。我按照 Next.js 上的说明进行操作:How to use source-map-explorer with Next.js

但我收到以下错误:

.next/static/chunks/styles.73849dc0d772a52b5056.js
  Unable to find a source map.
  See https://github.com/danvk/source-map-explorer/blob/master/README.md#generating-source-maps
.next/static/chunks/webpack-2ae0ca3384e062691226.js
  Unable to find a source map.
  See https://github.com/danvk/source-map-explorer/blob/master/README.md#generating-source-maps
.next/static/chunks/webpack-d9a7914a2067f7938722.js
  Unable to find a source map.
  See https://github.com/danvk/source-map-explorer/blob/master/README.md#generating-source-map

跨越所有 .js 块。由于某些插件,我无法真正弄清楚如何将内容直接添加到该module.exports部分中,所以我有:

const nextConfig = {
    productionBrowserSourceMaps: true,
    ...

我正在使用的withPlugins模块最后包括 nextConfig 。

  ],
  nextConfig
)

所以不确定这是把事情搞砸了还是完全是别的什么?

标签: javascriptwebpackpluginsnext.js

解决方案


对此的解决方案实际上是升级到 nextjs 版本 11。我们在版本 10 上,用于生成源映射的给定配置不起作用。


推荐阅读