microsoft / vscode-eslint

VSCode extension to integrate eslint into VSCode
MIT License
1.75k stars 336 forks source link

Server process exited with code 0 #1796

Open ljukas opened 8 months ago

ljukas commented 8 months ago

When running Eslint in vscode using flat config I get the following output:

[Info  - 10:43:56] ESLint server is starting.
[Info  - 10:43:56] ESLint server running in node v20.11.0
[Info  - 10:43:56] ESLint server is running.
[Info  - 10:43:56] ESLint library loaded from: /Users/xxx/app/node_modules/eslint/lib/unsupported-api.js
[Error - 10:43:57] Server process exited with code 0.

The eslint server keeps exiting without saying why.

This is my eslint.config.mjs

import eslint from '@eslint/js';
import prettierPlugin from 'eslint-plugin-prettier/recommended';
import reactPlugin from 'eslint-plugin-react';
import hooksPlugin from 'eslint-plugin-react-hooks';
import tseslint from 'typescript-eslint';

export default tseslint.config(
  eslint.configs.recommended,
  ...tseslint.configs.strictTypeChecked,
  {
    languageOptions: {
      parserOptions: {
        project: ['./apps/*/tsconfig.json', './packages/*/tsconfig.json'],
        tsconfigRootDir: import.meta.dirname,
      },
    },
  },
  {
    files: ['**/*.ts', '**/*.tsx'],
    plugins: {
      react: reactPlugin,
    },
    rules: reactPlugin.configs['jsx-runtime'].rules,
    settings: {
      react: {
        version: 'detect',
      },
    },
  },
  {
    files: ['**/*.tsx'],
    plugins: {
      'react-hooks': hooksPlugin,
    },
    rules: hooksPlugin.configs.recommended.rules,
  },
  {
    rules: {
      '@typescript-eslint/no-unused-vars': 'off',
    },
  },
  {
    ignores: [
      'eslint.config.mjs',
      'codegen.ts',
      'scripts/',
      '**/scripts/',
      '**/_generated/',
      '**/.*',
      '**/babel.config.js',
      '**/build/',
      '**/config-plugin-caret-color/app.plugin.js',
      '**/dist/',
      '**/expo-env.d.ts',
      '**/generated/',
      '**/metro.config.js',
      '**/metro.config.ts',
      '**/native/app.config.js',
      '**/native/app.config.ts',
      '**/native/colors.js',
      '**/native/plugins/',
      '**/tailwind.config.js',
    ],
  },
  prettierPlugin,
);

Here are some of my releveant vscode settings:

  "typescript.enablePromptUseWorkspaceTsdk": true,
  "eslint.experimental.useFlatConfig": true,
  "typescript.tsdk": "node_modules/typescript/lib",
  "eslint.workingDirectories": ["./packages/*", "./apps/*"],
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    "typescript",
    "typescriptreact",
    "graphql"
  ],

Eslint works in the terminal and it works for a second or two in vscode after restart of the eslint server.

I have a monorepo project with only one eslint.config.mjs in the root that handles the entire project, no seperate .eslintrc or anything

dbaeumer commented 8 months ago

Very hard to say without reproducible steps. Can you please provide me with a GitHub repository I can clone with a minimal repro case.

Celarye commented 8 months ago

For me the VSCode ESLint server exits with code 0 when I restart it (so not on VSCode's initial start). I still use the pre-v9.0 config.

ESLint VSCode logs:

[Info  - 22:36:53] ESLint server is starting.
[Info  - 22:36:53] ESLint server running in node v18.17.1
[Info  - 22:36:53] ESLint server is running.
[Info  - 22:36:53] ESLint library loaded from: /Users/celarye/Projects/Coding/GitHub/paperback-website/node_modules/eslint/lib/api.js
[Error - 22:36:54] Server process exited with code 0.

(Using "eslint": "^8.57.0")

ESLint config:

/* eslint-env node */
const config = {
  root: true,
  extends: [
    'eslint:recommended',
    'plugin:vue/vue3-recommended',
    '@vue/eslint-config-typescript',
    'prettier',
  ],
}

module.exports = config

One interesting thing to note is that even though it says it exited, it seems to work and show tips in VSCode:

image

Feel free to let me know if you would be interested in other stuff like my GitHub repository.

dbaeumer commented 8 months ago

A GitHub repository with a minimal setup I could clone would be helpful.

ljukas commented 8 months ago

Using vscode-eslint 2.4.4 it happens for me in this repo aswell, you might have to reload eslint for it to occur. The repo is straight copy of the original repo except I've removed all closed source code.

https://github.com/ljukas/vscode-eslint-repro

Thanks for looking into this

dbaeumer commented 8 months ago

Can you please also provide steps to reproduce

ljukas commented 8 months ago

Enter any .tsx file, open eslint output. You might need to reload the eslint server for it to exit out like above

vincentbriglia commented 8 months ago

can you run eslint from the cli and check if it actually matches any files? it looks like vscode-eslint crashes if it cannot find any files. if your cli-initiated eslint returns this or similar:

Oops! Something went wrong! :(

ESLint: 8.57.0

You are linting "src", but all of the files matching the glob pattern "src" are ignored.

vscode-eslint might also just crash because of it.

ljukas commented 8 months ago
image

For me it will lint files correctly in cli

dbaeumer commented 8 months ago

Here is what I see inside VS Code

Image

birgersp commented 7 months ago

Just want to chime in that I have the exact same error. eslint output yields:

[Info  - 11:22:59 AM] ESLint server is starting.
[Info  - 11:22:59 AM] ESLint server running in node v18.17.1
[Info  - 11:22:59 AM] ESLint server is running.
[Info  - 11:22:59 AM] ESLint library loaded from: /path-is-hidden/node_modules/eslint/lib/api.js
[Error - 11:23:00 AM] Server process exited with code 0.

I don't have any repos I could share to reproduce. But please let me know what I can do to help debug this.

birgersp commented 7 months ago

@dbaeumer

For me I could only get this error when I run the restart eslint server command.

So, here is how I reproduce the error with the repo that was provided:

image

image

image

dbaeumer commented 7 months ago

@birgersp your example is actually fine. The exit code 0 comes from the server that is restarted. For some reason it is printed into the new log. I will make this a info and ensure that it shows up in the correct log.

cihanselcuk commented 7 months ago

Hello,

I don't know if I should open a new thread for this, but I believe it is relevant.

Problem: Only way for me to view current problem (errors and warnings) on "Problems" tab is to 1- execute command "ESLint: restart ESLint server" 2- execute "Task: Run Task" and then "eslint: lint whole folder"

when I do this, current problems show up on problems bar. But after that if I open a file with problems and close it without fixing the problems, the related errors will disappear from the problems tab.

I checked out the output log of ESLint right after restarting it, it says:

[Info - 5:25:47 PM] ESLint server is starting. [Info - 5:25:47 PM] ESLint server running in node v18.17.1 [Info - 5:25:47 PM] ESLint server is running. [Error - 5:25:48 PM] Server process exited with code 0.

When I read it, I see that first it starts, then runs, and then exists with code 0 immediately. I except it to run continuously, so that I can view current problems as I write my code.

Any help is appreciated, thanks,

dbaeumer commented 7 months ago

@cihanselcuk actually the message Server process exited with code 0. comes from the server before restarting and this misleading message is fixed in the new version

From what you describe it is a setup problem with ESLint itself. Can you validate files successfully in the terminal using eslint from the ./node_modules/.bin` folder? If yes, please provide me with a GitHub repository a I can clone having a minimal repro case that demos what you are seeing

anilanar commented 7 months ago

I had the exact same problem. I switched to "Pre-release version" of vscode-eslint and that fixed it. Figured it out by considering why extension developer cannot reproduce it, obvious, because they use a different version!

Click cog next to eslint extension -> Switch to Pre-release version.

enkelmedia commented 6 months ago

I also got this error in one project, running another project (internal so can't share the source) on the same machine with almost the same dependencies. Are there any log files etc where one can see why we get the [Error - 3:13:40 PM] Server process exited with code 0. error?

dbaeumer commented 6 months ago

@enkelmedia have you seen this comment: https://github.com/microsoft/vscode-eslint/issues/1796#issuecomment-2025762741

It might be a false positive :-)

enkelmedia commented 6 months ago

@dbaeumer Nope, I get the error when it's startup just after loading the project/workspace. Are there any detailed logs to find out more about why this is happening?

dbaeumer commented 6 months ago

Only the ESLint output channel.

Can you provide me with a GitHub repository with a minimal setup I can clone that demos this. Then I can have a look.

Cauen commented 6 months ago

The same thing happened here and I managed to fix it.

My scenario was a monorepo and i was using a @monorepo-package/eslint-config packages/eslint-config in an app apps/backend without installing @monorepo-package/eslint-config as dependancy.

CraigglesO commented 6 months ago

I had the exact same problem. I switched to "Pre-release version" of vscode-eslint and that fixed it. Figured it out by considering why extension developer cannot reproduce it, obvious, because they use a different version!

Click cog next to eslint extension -> Switch to Pre-release version.

This is what I had to do for the extension to work correctly. Cheers.

taktran commented 6 months ago

Instead of using the pre release (which worked for me), you can also use the setting "eslint.experimental.useFlatConfig": true on the Release version

vuggy17 commented 6 months ago

I had the exact same problem. I switched to "Pre-release version" of vscode-eslint and that fixed it. Figured it out by considering why extension developer cannot reproduce it, obvious, because they use a different version!

Click cog next to eslint extension -> Switch to Pre-release version.

switch to pre-release version, then > restart eslint server change output from:

[Info  - 22:36:53] ESLint server is starting.
[Info  - 22:36:53] ESLint server running in node v18.18.2
[Info  - 22:36:53] ESLint server is running.
[Info  - 22:36:53] ESLint library loaded from: /home/vuggy17/workspace/idle2/node_modules/eslint/lib/api.js
[Error - 22:36:54] Server process exited with code 0.

to

[Info  - 1:41:27 PM] ESLint server is starting.
[Info  - 1:41:27 PM] ESLint server running in node v18.18.2
[Info  - 1:41:27 PM] ESLint server is running.
[Info  - 1:41:28 PM] ESLint library loaded from: /home/vuggy17/workspace/idle2/node_modules/eslint/lib/api.js
[Info  - 1:41:28 PM] Server process exited successfully
ewildee commented 5 months ago

I think I'm facing the same issue: ESLint works fine when started the first time (when opening VSCode or closing and reopening the project), but it stops working after a manual restart using 'ESLint: Restart ESLint server'.

Project details:

Steps to reproduce the problem (tried in a handful of projects):

I have enabled trace and debug and noticed that:

dbaeumer commented 5 months ago

@ewildee do you have a Github repository I can clone that demos this. It ensure that we use the same setup.

ewildee commented 5 months ago

@ewildee do you have a Github repository I can clone that demos this. It ensure that we use the same setup.

@dbaeumer Thanks for having a look. I've created a simple monorepo setup with a readme describing the steps to reproduce the problem: https://github.com/ewildee/test-20240529-vscode-eslint-minimal-monorepo

dbaeumer commented 5 months ago

@ewildee I was not able to reproduce this. Here is what I did

https://github.com/microsoft/vscode-eslint/assets/1931590/4ae0ed65-0207-4098-bb7e-c8384ce501fe

Is there anything special in the ESLint Output channel. Could you enable tracing using "eslint.trace.server": "messages"

ewildee commented 5 months ago

@dbaeumer It turns out my steps weren't 100% correct: Linting only doesn't work for files that haven't been opened before (and for new files), and only the first time they're opened. I've tested it on two different macOS systems.

https://github.com/microsoft/vscode-eslint/assets/3368251/d493f0d3-91d7-4d58-a83b-e359d9fc3706

The screen recording is from a MacBook running node v20 (instead of v22) without any custom ESLint settings (besides the ones in .vscode/settings.json + eslint.trace.server.

bpneal commented 5 months ago

The ESLint 9.*.* issue is present in Yarn 4+ (PnP enabled) but NOT in Yarn 4+ (with nodeLinker: node-modules). I have two examples (forked off of the above mono-repo example, one with Yarn 4 (pnp) and one with Yarn 4 (node modules).

Clearly there is an issue within the PNP infra that causes the ESLint flat config not to work as expected.

levrik commented 5 months ago

I'm experiencing the same issue that ESLint stops working randomly after some time. Restarting the ESLint server does not help and yields the results as written in the issue description. Restarting the extension host or VS Code completely fixes the issue. I'll enable tracing as suggested and report back.

ESLint 8.x, not using the new flat config. PNPM as package manager.

LeonardoGentile commented 5 months ago

Instead of using the pre release (which worked for me), you can also use the setting "eslint.experimental.useFlatConfig": true on the Release version

this doesn't fix it for me, I've been using it for a few months but still the problem persists

dbaeumer commented 5 months ago

@ewildee thanks for the additional steps. Was able to re-produce it. The problem is in the LSP libs: https://github.com/microsoft/vscode-languageserver-node/pull/1491

Need to produce new NPM modules first and then I can ship a new version of ESLint that addresses this.

dbaeumer commented 5 months ago

@bpneal this is a know issue in yarn. For the details see: https://github.com/yarnpkg/berry/issues/6219

mxvsh commented 5 months ago

@levrik did you find any solution? 👀

mxvsh commented 2 months ago

any update on this?

dbaeumer commented 2 months ago

In which regard. The process exit with code 0 has been fixed and the Yarn issue has been fixed as well.

mattkrins commented 1 month ago

In which regard. The process exit with code 0 has been fixed and the Yarn issue has been fixed as well.

So should this be in the output when restarting the eslint server?

[Info  - 12:50:37 AM] ESLint server is starting.
[Info  - 12:50:37 AM] ESLint server running in node v20.15.1
[Info  - 12:50:37 AM] ESLint server is running.
[Info  - 12:50:38 AM] Server process exited successfully
dbaeumer commented 1 month ago

I noticed that this might still happen based on the async behavior. Should check the process id to filter those on restart.

murshed-panorama commented 1 month ago

In which regard. The process exit with code 0 has been fixed and the Yarn issue has been fixed as well.

So should this be in the output when restarting the eslint server?

[Info  - 12:50:37 AM] ESLint server is starting.
[Info  - 12:50:37 AM] ESLint server running in node v20.15.1
[Info  - 12:50:37 AM] ESLint server is running.
[Info  - 12:50:38 AM] Server process exited successfully

I'm having the same issue as @mattkrins. Should the server stay running and not exit immediately?

gislerro commented 1 month ago

I have no idea how the eslint server can use a node version that isn't even installed in my container but uses the node version of my host (v20.16.0). It then loads the eslint library from the node_modules in the devcontainer installed with node v22.9.0?

and setting eslint.nodePath in settings.json has no effect at all?

I don't even have the eslint extension installed on my host?

[Info  - 6:24:32 AM] ESLint server is starting.
[Info  - 6:24:32 AM] ESLint server running in node v20.16.0
[Info  - 6:24:32 AM] ESLint server is running.
[Info  - 6:24:32 AM] ESLint library loaded from: /path/to/my/project/node_modules/eslint/lib/api.js
[Info  - 6:24:33 AM] Server process exited successfully

It's 2024 and js/ts development is still a hot mess...

and enabling the lint task with "eslint.lintTask.enable": true does in fact not create a task, it just silently fails without any sort of error indication, amazing👍

dbaeumer commented 1 month ago

VS Code (via Electron) ships its own version of Node (20.16.0). You can control the version used using the eslint.runtime setting. The eslint extension needs to run on the host otherwise that output wouldn't appear. Do you have settings sync on, which syncs used extensions as well?

gislerro commented 1 month ago

VS Code (via Electron) ships its own version of Node (20.16.0). You can control the version used using the eslint.runtime setting. The eslint extension needs to run on the host otherwise that output wouldn't appear. Do you have settings sync on, which syncs used extensions as well?

I have settings sync on.

I just can't get the eslint plugin to lint my entire project. I have these settings on:

Image

Running eslint on the terminal the errors but vscode eslint doesn't pick them up

dbaeumer commented 1 month ago

The plugin is only validating the open files. There is no good support to validate the whole project. See https://github.com/microsoft/vscode-eslint/issues/91

gislerro commented 1 month ago

The plugin is only validating the open files. There is no good support to validate the whole project. See #91

It's been 8 years and you cannot reliably configure linting the most popular programming language with its most popular linter in the most popular code editor...

Please don't take offense as the (sole?) maintainer of this plugin, you should receive more support.

It just baffles me that I have a hassle-free editor experience in any other language

dbaeumer commented 1 month ago

Doing this for the whole project continuously is not very well supported by ESLint either. This is why nothing has happened in that realm. In addition there is no common style how people lint their whole project. Some call eslint directly, some have scripts and other script in package.json. VS Code comes with a great task system and the best solution is still to create a task that run ESLint the same way you would execute it in a terminal.