question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

nextConfig issue while building or running the project

See original GitHub issue

Verify canary release

  • 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,
);

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:23
  • Comments:29 (2 by maintainers)

github_iconTop GitHub Comments

24reactions
enkheecommented, Sep 9, 2022

This bug is also present in next@12.3

22reactions
umararshad4commented, Jul 31, 2022

instead, i’m getting errors for those flags which i’m not using. On Mon, 1 Aug 2022 at 12:06 AM, Franklys Guimarães @.> wrote: Hello, I had the same problem, but I solved it when I removed these flags from next.config, because they are valid [image: image] https://user-images.githubusercontent.com/42286289/182040479-9f191b3d-76bb-485b-b11a-d05ccd69d4e2.png — Reply to this email directly, view it on GitHub <#39161 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AISB4OQ3CGVWIX2CX6LNGMDVW3BT7ANCNFSM55ACCBIA . You are receiving this because you authored the thread.Message ID: @.>

if you are using window you need to download some c++ binaries files

Read more comments on GitHub >

github_iconTop Results From Across the Web

warning Invalid next.config.js when running project - nextJs
"The root value has an unexpected property, autoComplete, which is not in the list of allowed properties (amp, ..." I wrapped it into...
Read more >
Setting a custom build directory - next.config.js
Now if you run next build Next.js will use build instead of the default .next folder. distDir should not leave your project directory....
Read more >
Environment Variables in Next.js - Frontend Digest
When developing locally, Next.js will load environment variables from a file ... Create a file called next.config.js at the root of your project...
Read more >
How to Build Scalable Architecture for your Next.js Project
It's recommended (but not required) to close your dev server when running a Next.js build. Most of the time there is no issue...
Read more >
next-pwa - npm
Start using next-pwa in your project by running `npm i next-pwa`. ... during build, please consider upgrade to webpack5 in next.config.js .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found