Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug?]: Yarn pnp / sdk generation doesn't work with ESLint new flat config support #6219

Open
1 task
dbaeumer opened this issue Apr 11, 2024 · 7 comments
Open
1 task
Labels
bug Something isn't working

Comments

@dbaeumer
Copy link

dbaeumer commented Apr 11, 2024

Self-service

  • I'd be willing to implement a fix

Describe the bug

ESLint's new flat config support fails to load when using flat config module files. It does work when using common JS config files.

This bahviour gor reported against the VS Code ESLint extension (see microsoft/vscode-eslint#1620) but it is independent of the VS Code extension and can be reproduce using the eslint npm package standalone

To reproduce

Setup:

package.json

{
  "name": "yarn-eslint-test",
  "packageManager": "yarn@4.1.1",
  "type": "module",
  "scripts": {
    "eslint": "eslint test.js"
  },
  "devDependencies": {
    "@eslint/js": "^8.57.0",
    "eslint": "^8.57.0"
  }
}

eslint.config.mjs

import js from "@eslint/js";

export default [
	js.configs.recommended,
	{
		files: ["**/*.js"],
		rules: {
			"no-var": "error",
		}
	}
];

test.js

var x = 10;

Run the following commands in a shell:

> corepack enable
> yarn install
> yarn dlx @yarnpkg/sdks vscode
> export NODE_PATH=".yarn/sdks"

Setting the NODE_PATH is equivalent to setting the VS Code eslint.nodePath setting.

start node REPL and execute the following commands (to ensure to mimic the executing since a VS Code extension):

require.resolve('eslint');

We will load the eslint npm module from .yarn/sdks

const library = require('eslint');
async function main() { const eslint = new (await library.loadESLint({ useFlatConfig: true }))(); const report = await eslint.lintText(`var test = "hello";`); console.log(report); }
main().catch((error) => { console.error(error); process.exitCode = 1; });

You get:

Image

Expected behavior: the eslint.config.mjs can successfully be loaded. Converting the config file to cjs makes everything work.

Environment

System:
OS: Linux 5.15 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700K
Binaries:
Node: 18.18.2 - /tmp/xfs-e72dc863/node
Yarn: 4.1.1 - /tmp/xfs-e72dc863/yarn
npm: 9.8.1 - ~/.nvs/default/bin/npm

Additional context

No response

@dbaeumer dbaeumer added the bug Something isn't working label Apr 11, 2024
@dbaeumer dbaeumer changed the title [Bug?]: Yarn pnp / sdk generation doesn;t work with ESLint new flat config support [Bug?]: Yarn pnp / sdk generation doesn't work with ESLint new flat config support Apr 11, 2024
qwell added a commit to qwell/symbol.wtf that referenced this issue Apr 20, 2024
@dbaeumer
Copy link
Author

dbaeumer commented May 6, 2024

Any news on this. This issue is basically blocking flat config adaption with VS Code / eslint extension.

@arcanis
Copy link
Member

arcanis commented May 6, 2024

I'm looking right now at migrating this repository to Eslint 9; I'll take a look at that at the same time.

@arcanis
Copy link
Member

arcanis commented May 6, 2024

I'm experimenting in #6278 - it seems to work with your (very detailed, thanks a lot!) reproduction, but it still fails in VSCode. Trying to figure out what might be different.

@arcanis
Copy link
Member

arcanis commented May 6, 2024

I think I figured it out - v18.19.0 is the first version that supports register (to add ESM loaders at runtime), and VSCode ships with Electron 28, which is tied to Node 18.18. So unfortunately I'm afraid we can't do much right now 🫤

@dbaeumer
Copy link
Author

dbaeumer commented May 7, 2024

@arcanis thanks for looking into this.

Which node version is required to make this work. I tested the same steps under Node 20.10.0 and it produces the same exception.

Image

@arcanis
Copy link
Member

arcanis commented May 7, 2024

You need both my PR (#6278) and Node >v20.6.0, v18.19.0; you can try it by cloning my branch and running your repro in this repo.

@dbaeumer
Copy link
Author

dbaeumer commented May 7, 2024

Thanks!

We will move to Electron 29 in the near future which will come with NodeJS 20.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants