检测到无效的 next.config.js 选项:根值具有意外的属性 defaultConfig,该属性不在允许的属性列表中

问题描述 投票:0回答:1

这就是我遇到的问题。

- warn Invalid next.config.js options detected: 
- warn     The root value has an unexpected property, defaultConfig, which is not in the list of allowed properties (amp, analyticsId, assetPrefix, basePath, cleanDistDir, compiler, compress, configOrigin, crossOrigin, devIndicators, distDir, env, eslint, excludeDefaultMomentLocales, experimental, exportPathMap, generateBuildId, generateEtags, headers, httpAgentOptions, i18n, images, modularizeImports, onDemandEntries, optimizeFonts, output, outputFileTracing, pageExtensions, poweredByHeader, productionBrowserSourceMaps, publicRuntimeConfig, reactStrictMode, redirects, rewrites, sassOptions, serverRuntimeConfig, skipMiddlewareUrlNormalize, skipTrailingSlashRedirect, staticPageGenerationTimeout, swcMinify, target, trailingSlash, transpilePackages, typescript, useFileSystemPublicRoutes, webpack).
- warn See more info here: https://nextjs.org/docs/messages/invalid-next-config

这是我的 next.config.js 文件:

/** @type {import('next').NextConfig} */
const nextConfig = {
    reactStrictMode: true,
    webpack(config) {
        const fileLoaderRule = config.module.rules.find((rule) => rule.test?.test?.(".svg"));
        config.module.rules.push(
            {
                ...fileLoaderRule,
                test: /\.svg$/i,
                resourceQuery: /url/,
            },
            {
                test: /\.svg$/i,
                issuer: /\.[jt]sx?$/,
                resourceQuery: { not: /url/ },
                use: ["@svgr/webpack"],
            }
        );
        fileLoaderRule.exclude = /\.svg$/i;
        return config;
    },
};

// module.exports = nextConfig;

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

module.exports = (phase, defaultConfig) => {
    return withBundleAnalyzer(defaultConfig);
};

如果您纠正我的错误并解释一下,我会很高兴:)谢谢

我希望 svgr 和bundle-analyzer 能够协同工作。

reactjs next.js config bundle
1个回答
0
投票

我一般都是这么写的,没有任何问题

// ... rest of the code..

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

module.exports = withBundleAnalyzer(nextConfig)
© www.soinside.com 2019 - 2024. All rights reserved.