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

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

我正在构建打字稿的下一个项目。如果我将此配置文件保留为

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"]
}

下一个.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,
  },
};
typescript next.js server-side-rendering
2个回答
10
投票

似乎使用

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

存在原生支持

next.config.ts
的问题(更像是请求)。 这里是关于它的问题,它有其他开发者的一些解决方案


0
投票

从 Next v15.0.0 开始

next.config.ts
原生支持开箱即用。

© www.soinside.com 2019 - 2024. All rights reserved.