Repository: next.js
Issue: nextConfig issue while building or running the project 
Labels: linear: next

### Verify canary release

- [X] I verified that the issue exists in the latest Next.js canary release

### Provide environment information

```  
Operating System:
      Platform: darwin
      Arch: x64
      Version: Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:37 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T6000
    Binaries:
      Node: 14.19.0
      npm: 6.14.16
      Yarn: 1.22.18
      pnpm: N/A
    Relevant packages:
      next: 12.2.4-canary.8
      eslint-config-next: 11.0.1
      react: 17.0.2
      react-dom: 17.0.2
```

### What browser are you using? (if relevant)

_No response_

### How are you deploying your application? (if relevant)

_No response_

### Describe the Bug

next config file is throwing error while building and warning while development
```
warn  - Invalid next.config.js options detected: 
[
  {
    "instancePath": "",
    "schemaPath": "#/additionalProperties",
    "keyword": "additionalProperties",
    "params": {
      "additionalProperty": "webpack5"
    },
    "message": "must NOT have additional properties"
  },
  {
    "instancePath": "",
    "schemaPath": "#/additionalProperties",
    "keyword": "additionalProperties",
    "params": {
      "additionalProperty": "target"
    },
    "message": "must NOT have additional properties"
  },
  {
    "instancePath": "",
    "schemaPath": "#/additionalProperties",
    "keyword": "additionalProperties",
    "params": {
      "additionalProperty": "webpackDevMiddleware"
    },
    "message": "must NOT have additional properties"
  },
  {
    "instancePath": "",
    "schemaPath": "#/additionalProperties",
    "keyword": "additionalProperties",
    "params": {
      "additionalProperty": "configOrigin"
    },
    "message": "must NOT have additional properties"
  },
  {
    "instancePath": "/amp/canonicalBase",
    "schemaPath": "#/properties/amp/properties/canonicalBase/minLength",
    "keyword": "minLength",
    "params": {
      "limit": 1
    },
    "message": "must NOT have fewer than 1 characters"
  },
  {
    "instancePath": "/assetPrefix",
    "schemaPath": "#/properties/assetPrefix/minLength",
    "keyword": "minLength",
    "params": {
      "limit": 1
    },
    "message": "must NOT have fewer than 1 characters"
  },
  {
    "instancePath": "/experimental/outputFileTracingRoot",
    "schemaPath": "#/properties/experimental/properties/outputFileTracingRoot/minLength",
    "keyword": "minLength",
    "params": {
      "limit": 1
    },
    "message": "must NOT have fewer than 1 characters"
  },
  {
    "instancePath": "/i18n",
    "schemaPath": "#/properties/i18n/type",
    "keyword": "type",
    "params": {
      "type": "object"
    },
    "message": "must be object"
  }
] 
See more info here: https://nextjs.org/docs/messages/invalid-next-config
```

### Expected Behavior

the build should not fail and dev command should work without any warning

### Link to reproduction

it's a private repo

### To Reproduce

this is how next config file looks like: 

```
const shell = require('shelljs');
const withPlugins = require('next-compose-plugins');
const optimizedImages = require('next-optimized-images');
const FilterWarningsPlugin = require('webpack-filter-warnings-plugin');
const RollbarSourcemapPlugin = require('rollbar-sourcemap-webpack-plugin');

const isDev = process.env.NODE_ENV !== 'production';

const packages = JSON.parse(
  shell.exec('npx lerna list --all --json', {
    silent: true,
  }).stdout,
);

const packageNames = packages
  .reduce((a, currentPackage) => [...a, currentPackage.name], [])
  .filter(item => item.includes('@assets'));

const withTM = require('next-transpile-modules')(packageNames);

/**
 * @type {import('next').NextConfig}
 */
const nextConfig = {
  async redirects() {
    return [
      {
        source: '/signup',
        destination: '/',
        permanent: false,
      },
    ];
  },
  images: {
    disableStaticImages: true,
    dangerouslyAllowSVG: true,
    contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;",
  },
  productionBrowserSourceMaps: true,
  generateBuildId: async () => {
    if (process.env.NEXT_PUBLIC_COMMIT_HASH) {
      return process.env.NEXT_PUBLIC_COMMIT_HASH;
    }
    // return null to use default next.js build id if there is no commit hash
    return null;
  },
  assetPrefix: isDev ? 'http://localhost:3000' : '',
  webpack: (config, { dev, buildId }) => {
    config.module.rules.push({
      test: /\.(eot|woff|woff2|ttf)$/,
      type: 'asset/resource',
    });

    config.plugins.push(
      new FilterWarningsPlugin({
        exclude: /mini-css-extract-plugin[^]*Conflicting order between:/,
      }),
    );

    // to upload source maps to rollbar, we follow this example as reference
    // https://github.com/thredup/rollbar-sourcemap-webpack-plugin/blob/c7569ddf99fc01041f12a3d4b2998ea0f93a8dbe/examples/next-js/next.config.js
    if (!dev) {
      // Generate a common `id` to be used when initializing Rollbar & when uploading the sourcemaps.
      // This could be any common value, as long as it is used in `_document.js` when initializing Rollbar.
      const codeVersion = JSON.stringify(buildId);

      config.plugins.push(
        new RollbarSourcemapPlugin({
          accessToken: process.env.ROLLBAR_ACCESS_TOKEN,
          version: codeVersion,
          publicPath: `${process.env.FRONTEND_ENDPOINT}/_next/`,
        }),
      );
    }

    return config;
  },
};

module.exports = withPlugins(
  [[withTM], [optimizedImages, { optimizeImagesInDev: true }]],
  nextConfig,
);
```

<sub>[NEXT-1371](https://linear.app/vercel/issue/NEXT-1371/nextconfig-issue-while-building-or-running-the-project)</sub>