10

I am building typescript next project. if I keep this config file as next.config.js, I get a warning in tsconfig.json saying "next.config.ts not found". so tsconfig.json has warning sign on the {}.

If I change the extension to .ts, when I start the project, I get this error:

"Error: Configuring Next.js via 'next.config.ts' is not supported. Please replace the file with 'next.config.js'. "

I am confused and I do not what to do.

ts.config.json

{ 
  "compilerOptions": {
    "target": "es6",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"]
    },
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "sourceMap": true,
    "removeComments": true,

    "jsx": "preserve"
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
  "exclude": ["node_modules"]
}

next.config.ts

const path = require("path");
const Dotenv = require("dotenv-webpack");

module.exports = {
  env: {
    AUTH0_NAMESPACE: process.env.AUTH0_NAMESPACE,
    BASE_URL: process.env.BASE_URL,
  },
};
Yilmaz
  • 35,338
  • 10
  • 157
  • 202
  • can you post the contents of your tsconfig.json and scripts you use to build it? right now I cannot reproduce the issue, please refer to [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) – Krzysztof Krzeszewski Dec 16 '20 at 10:46
  • @KrzysztofKrzeszewski you are right. I edited – Yilmaz Dec 16 '20 at 11:05

1 Answers1

7

It seems that using next.config.ts slows down bootup, since you have to compile it yourself, or at least that's what the members of the next.js repo said.

There was an issue (more like a request) to support next.config.ts natively. Here is the issue about it, it has some solutions from other developers