错误:不支持通过“next.config.ts”配置 Next.js。请将文件替换为“next.config.js”

Yil*_*maz 13 typescript server-side-rendering next.js

我正在构建下一个项目的打字稿。如果我将此配置文件保留为next.config.js,我会收到一条警告tsconfig.json“未找到 next.config.ts”。所以 tsconfig.json 上有警告标志{}

如果我将扩展名更改为.ts,当我启动项目时,我会收到以下错误:

“错误:不支持通过‘next.config.ts’配置 Next.js。请将该文件替换为‘next.config.js’。”

我很困惑,我不知道该怎么办。

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"]
}
Run Code Online (Sandbox Code Playgroud)

下一个.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,
  },
};
Run Code Online (Sandbox Code Playgroud)

小智 10

似乎使用next.config.ts会减慢启动速度,因为你必须自己编译它,或者至少 next.js 存储库的成员是这么说的。

存在一个需要next.config.ts本地支持的问题(更像是一个请求)。 是关于它的问题,它有其他开发人员的一些解决方案