vite: Parsing error: ESLint was configured to run on `/vite.config.ts` using `parserOptions.project`:

Describe the bug

pnpm create vite react typescript-swc

Reproduction

https://stackblitz.com/edit/vitejs-vite-psmxmw?file=tsconfig.node.json

Steps to reproduce

No response

System Info

OS: macOS 12.5.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 101.81 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.16.0 - ~/.nvm/versions/node/v16.16.0/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 8.11.0 - ~/.nvm/versions/node/v16.16.0/bin/npm
    pnpm: 8.5.1 - /opt/homebrew/bin/pnpm
    Watchman: 2023.02.27.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 114.0.5735.198
    Safari: 15.6.1
  npmPackages:
    @vitejs/plugin-react-swc: ^3.3.2 => 3.3.2 
    vite: ^4.4.0 => 4.4.0

Used Package Manager

pnpm

Logs

No response

Validations

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 4
  • Comments: 16 (1 by maintainers)

Most upvoted comments

having the same issue inside src folder, another fix is to add src in ignorePatterns: ignorePatterns: [".eslintrc.cjs", "vite.config.ts", "src"], in .eslintrc.cjs.

Problem solved ./.eslintrc.cjs :change parserOptions.project to [‘./tsconfig.json’, ‘./tsconfig.node.json’]

https://github.com/vitejs/vite/issues/13747#issuecomment-1636870022


I have discovered a new solution !

./.eslintrc.cjs :change parserOptions.project to [‘./tsconfig.json’, ‘./tsconfig.node.json’]


tsconfig.node.json

- "include": ["vite.config.ts"]
+ "include": ["vite.config.ts", ".eslintrc.cjs"]

By the way, another thing: If you use node.js in vite

xxx.js, not xxx.cjs

__dirname is not defined in es module scope

You need to modify it to the following code :

import path from 'path'
import { fileURLToPath } from 'url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

Having the same issue

Same issue but using yarn.

@vaynevayne I am having the same issue trying to start a new vite react typescript project.