【问题标题】:Invalid next.config.js options detected-NextJS检测到无效的 next.config.js 选项-NextJS
【发布时间】:2022-11-24 19:20:38
【问题描述】:
warn  - Invalid next.config.js options detected:
The root value has an unexpected property, target, which is not in the list of allowed properties (amp, analyticsId, assetPrefix, basePath, cleanDistDir, compiler, compress, crossOrigin, devIndicators, distDir, env, eslint, excludeDefaultMomentLocales, experimental, exportPathMap, generateBuildId, generateEtags, headers, httpAgentOptions, i18n, images, onDemandEntries, optimizeFonts, output, outputFileTracing, pageExtensions, poweredByHeader, productionBrowserSourceMaps, publicRuntimeConfig, reactStrictMode, redirects, rewrites, sassOptions, serverRuntimeConfig, staticPageGenerationTimeout, swcMinify, trailingSlash, typescript, useFileSystemPublicRoutes, webpack).

Error: The "target" property is no longer supported in next.config.js.

这是我的 next.config.js

const withBundleAnalyzer = require("@next/bundle-analyzer")({
  enabled: process.env.ANALYZE === "true",
});

module.exports = withBundleAnalyzer({
  target: "serverless",
  env: {
    BASE_URL: process.env.BASE_URL,
  },

  webpack(conf) {
    conf.module.rules.push({
      test: /\.svg$/,
      use: [
        {
          loader: "@svgr/webpack",
          options: {
            svgoConfig: {
              plugins: [
                {
                  // Enable figma's wrong mask-type attribute work
                  removeRasterImages: false,
                  removeStyleElement: false,
                  removeUnknownsAndDefaults: false,
                  // Enable svgr's svg to fill the size
                  removeViewBox: false,
                },
              ],
            },
          },
        },
      ],
    });
    conf.resolve.modules.push(__dirname);
    return conf;
  },
});

我以为是模块问题,所以我重新安装了它,但确实如此。我尝试按照按钮链接上的格式进行操作,但我不知道该怎么做。

【问题讨论】:

    标签: typescript next.js


    【解决方案1】:

    错误信息很明确:

    Error: The "target" property is no longer supported in next.config.js.
    

    target: "serverless" 属性在 nextJs 版本 12 中被弃用,根据这个 issue,建议删除这个属性并使用 output: "standalone" 代替。

    另请参阅 nextJs 文档中的 section 以获取有关它的更多信息。

    【讨论】:

      猜你喜欢
      • 2022-11-11
      • 2022-11-11
      • 1970-01-01
      • 2019-07-24
      • 1970-01-01
      • 2019-02-20
      • 2021-12-15
      • 2021-03-06
      • 2021-04-17
      相关资源
      最近更新 更多