网站搜索

reactjs - nextjs 强制将 ES6 转译为 ES5 忽略 tsconfig


Nextjs 在编译时忽略 tsconfig 的 target 选项。ES6 类和箭头函数转译为函数。

当 next build 在终端中写入时

info  - Using tsconfig file: ./tsconfig.json

并且路径别名不会导致错误。所以我的 tsconfig 正在应用。但是 nextjs 转译所有箭头函数、类等等

// tsconfig.json
{
    "compilerOptions": {
        "target": "es2020",
        "lib": [
            "webworker",
            "dom",
            "dom.iterable",
            "esnext"
        ],
        "allowJs": true,
        "skipLibCheck": true,
        "strict": true,
        "forceConsistentCasingInFileNames": true,
        "noEmit": true,
        "esModuleInterop": true,
        "module": "esnext",
        "moduleResolution": "Node",
        "resolveJsonModule": true,
        "isolatedModules": true,
        "jsx": "preserve",
        "baseUrl": ".",
        "paths": {
            "@/*": [
                "./*"
            ],
            "src/*": [
                "src/*"
            ],
        },
        "incremental": true
    },
    "exclude": [
        "node_modules"
    ],
    "include": [
        "next-env.d.ts",
        "**/*.ts",
        "**/*.tsx"
    ]
}