【问题标题】:Error: Configuring Next.js via 'next.config.ts' is not supported. Please replace the file with 'next.config.js'错误:不支持通过“next.config.ts”配置 Next.js。请将文件替换为“next.config.js”
【发布时间】:2021-05-13 16:37:24
【问题描述】:

我正在构建 typescript 下一个项目。如果我将此配置文件保留为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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2022-12-03
    • 1970-01-01
    • 1970-01-01
    • 2015-11-03
    • 2019-12-29
    • 2019-07-21
    • 1970-01-01
    • 2021-10-24
    • 1970-01-01
    相关资源
    最近更新 更多