You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS Code创建新文件时ESLint报错(Turborepo+React-i18next环境)

解决Turborepo + Next.js + react-i18next的ESLint路径错误问题

实用修复方案

1. 给ESLint配置pnpm依赖解析器

在项目根目录的.eslintrc.js(或.eslintrc.json)中添加pnpm专属的解析配置,让ESLint适配pnpm的扁平依赖结构:

module.exports = {
  settings: {
    'import/resolver': {
      node: {
        paths: ['src'],
        extensions: ['.js', '.jsx', '.ts', '.tsx'],
      },
      pnpm: {}, // 启用pnpm解析逻辑
    },
  },
};

如果还没安装对应依赖,先执行:

pnpm add -D eslint-import-resolver-pnpm

2. 修正TypeScript的类型文件路径配置

在根目录或Next.js应用的tsconfig.json里,明确指定类型文件的根路径,避免ESLint误判路径:

{
  "compilerOptions": {
    "typeRoots": ["./node_modules/@types", "./node_modules/react-i18next/dist"]
  }
}

3. 关闭ESLint自动重启,手动刷新服务

打开VS Code设置,搜索ESLint: Auto Restart并关闭。之后每次新建文件,不用重启VS Code,直接按Ctrl+Shift+P(Windows/Linux)或Cmd+Shift+P(Mac),执行ESLint: Restart ESLint Server即可清除错误。

4. 彻底清理缓存后重装依赖

执行以下命令清理Turborepo和pnpm的缓存,重新安装依赖:

turbo clean
pnpm store prune
pnpm install

5. 给Next.js添加webpack模块解析配置

在Next.js应用的next.config.js中补充webpack配置,强制指定模块查找路径:

const path = require('path');

const nextConfig = {
  webpack: (config) => {
    config.resolve.modules.push(path.resolve('./node_modules'));
    return config;
  },
};

module.exports = nextConfig;

内容的提问来源于stack exchange,提问作者Alesij

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 21:39:53