berry: [Bug?]: Yarn pnp / sdk generation doesn't work with ESLint new flat config support
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 https://github.com/microsoft/vscode-eslint/issues/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:
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® Core™ 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
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 16
- Comments: 38 (15 by maintainers)
Commits related to this issue
- Switch to cjs for testing. See https://github.com/yarnpkg/berry/issues/6219 — committed to qwell/symbol.wtf by qwell 3 years ago
- Adds support for ESM loaders to the SDKs (#6278) ## What's the problem this PR addresses? ESM loaders aren't supported by the sdks because we only `require().setup()` but we don't `register()` th... — committed to yarnpkg/berry by arcanis 2 years ago
- $ yarn upgrade-interactive $ yarn add -D @typescript-eslint/{parser,eslint-plugin}@npm:rc-v8 $ yarn dedupe $ yarn set version latest # fix https://github.com/yarnpkg/berry/issues/6219 * remove `yarnPa... — committed to n0099/open-tbm by n0099 2 years ago
- $ yarn upgrade-interactive $ yarn add -D @typescript-eslint/{parser,eslint-plugin}@npm:rc-v8 $ yarn dedupe $ yarn set version latest # fix https://github.com/yarnpkg/berry/issues/6219 * remove `yarnPa... — committed to n0099/open-tbm by n0099 2 years ago
I’m looking right now at migrating this repository to Eslint 9; I’ll take a look at that at the same time.
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 🫤I just triggered a release. Using the 4.3.0 the original test case doesn’t crash anymore. In case you still face issues, please make sure you use both Yarn 4.3 and the SDK 3.1.3. If you do, open a new thread (let’s not reuse this one, I’d like to keep investigation separate as something that may look related may be a completely different bug).
For reference, here’s a script to easily run the commands from the op; note I updated
packageManagerto 4.3:Is there any solution? Or not use other packages manager?
#6278 is already merged 4 days ago, so just running
yarn dlx @yarnpkg/sdks vscodeshould be enough by now.I can reproduce this without the extension using the sdk version from https://github.com/yarnpkg/berry/pull/6278 and running
If i run the config through
yarn nodeit can resolve all modules.UPDATE It works, i only installed the updated sdk. But i needed to build the full cli so the
.pnp.loader.mjsgets updated aswell.@n0099 Do not use
yarn dlx -p '@yarnpkg/sdks@https://github.com/yarnpkg/berry#head=mael/eslint-flat-config&workspace=@yarnpkg/sdks' @yarnpkg/sdks vscodeInstead build the cli from the correct branch https://github.com/yarnpkg/berry/tree/mael/eslint-flat-config (yarn build:cli) yourself and link the new cli in your.yarnrc.ymlwithyarnPath. It should work.I can confirm the same as @n0099. I still get
ERR_MODULE_NOT_FOUNDusing multiple setups with https://github.com/yarnpkg/berry/pull/6278 and node@20.9:eslint.experimental.useFlatConfig: true), eslint@^9.4.0 - ❌eslint.experimental.useFlatConfig: true), eslint@^8.57.0 - ❌I debugged a little and it is still unable to find
findPnpApi()in theresolvehook for me when executed in the extension. Cli execution works fine.Maybe i am missing something in my setup?
Happy to provide more info if needed 😊
You need both my PR (https://github.com/yarnpkg/berry/pull/6278) and Node >v20.6.0, v18.19.0; you can try it by cloning my branch and running your repro in this repo.