vite-plugin-eslint icon indicating copy to clipboard operation
vite-plugin-eslint copied to clipboard

No error on `vite serve` but errors on `vite build`

Open kelzenberg opened this issue 1 year ago • 4 comments

I cannot get an error out of vite serve on an empty project with a linter error purposely build in, but vite build does display the error (twice).

Versions

vite: 4.5.0 vite-plugin-eslint 1.8.1 eslint 8.53.0

Vite config

import eslint from 'vite-plugin-eslint';

/** @type {import('vite').UserConfig} */
export default {
  root: './src',
  envDir: '../',
  build: { outDir: '../dist', emptyOutDir: true },
  plugins: [eslint()],
};

index.js

const foo = 'bar'; // shows ESLint `no-unused-vars` error
console.log("Hello world!"); // shows ESLint `no-console` warning

Vite console output

> vite build

vite v4.5.0 building for production...
✓ 2 modules transformed.
✓ built in 1.66s
[vite-plugin-eslint]
/Users/dedacted/src/index.js
  1:7  error    'foo' is assigned a value but never used  no-unused-vars
  2:1  warning  Unexpected console statement              no-console

✖ 2 problems (1 error, 1 warning)

but...

> vite serve


  VITE v4.5.0  ready in 564 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  press h to show help

What am I missing here?

kelzenberg avatar Nov 06 '23 17:11 kelzenberg

Came here for the very same problem. I'd love to know what to do as well.

gdpdils avatar Nov 07 '23 14:11 gdpdils

Right now, I activated

plugins: [eslint({ lintOnStart: true })],

in the vite.config.js because my project is still small and there's no noticeable latency on server start yet. This is obviously not a long-term solution...

kelzenberg avatar Nov 13 '23 12:11 kelzenberg

I saw similar behavior! Did navigating to http://localhost:5173/ make the error show up? That works for me.

tthornton3-chwy avatar Nov 17 '23 01:11 tthornton3-chwy

@tthornton3-chwy For me, the local server only shows an error if one of the files changes and this change produces the error.

kelzenberg avatar Dec 03 '23 12:12 kelzenberg