berry: [Bug?]: Yarn pnp fails with synckit and prettier plugin in eslint context
Self-service
- I’d be willing to implement a fix
Describe the bug
Yarn pnp can’t load synckit worker hence prettier plugin fails to run.
Why do I file this against yarn? Everything works as expected when installing the dependencies with npm.
To reproduce
Use NodeJS 20.9.0
Clone https://github.com/shermify/eslint-plugin-repro
> yarn install
> 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())(); const report = await eslint.lintText(`var test = "hello";`); console.log(report); }
main().then(() => { console.log('Promise resolved'); } ).catch((error) => { console.error(error); process.exitCode = 1; });
Observe: the promise never resolves. You can’t even terminate NodeJS using Ctrl+C. You have to kill it.
I debugged it in the context of the VS Code ESLint extension and the findings are here: https://github.com/microsoft/vscode-eslint/issues/1856#issuecomment-2162280404 and in the following comments.
Environment
System: OS: Linux 5.15 Debian GNU/Linux 11 (bullseye) 11 (bullseye) CPU: (20) x64 12th Gen Intel® Core™ i7-12700K Binaries: Node: 20.9.0 - /tmp/xfs-426f4fe7/node Yarn: 4.3.0 - /tmp/xfs-426f4fe7/yarn npm: 10.1.0 - ~/.nvs/default/bin/npm pnpm: 9.1.1 - /usr/local/share/npm-global/bin/pnpm
Additional context
No response
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 16
- Comments: 21 (5 by maintainers)
Because the Node.js ESM loader pipeline is still broken 😞
Digging into the issue, it seems the
--loaderflag that SyncKit adds is ignored by thenew Workerconstructor, which seems to be the subject of https://github.com/nodejs/node/issues/47747. That’s what causes theERR_MODULE_NOT_FOUNDerror when dynamically importingprettier, which in turns causes a deadlock probably because of a faulty error handling code somewhere in the Node.js internals.I opened an issue on SyncKit (https://github.com/un-ts/synckit/issues/174) to suggest a workaround.
Yes and no. The Node.js ESM loader implementation is quite fluctuating, so bugs sometimes appear and get fixed on later versions (for instance some 22.x versions introduce a deadlock with some other loaders). As a result problems are very rarely about PnP itself, but more the APIs we’re given to integrate with ESM in Node.
I managed to repro - I was running
yarn node(which translates intonode --require ./.pnp.cjs --loader ./.pnp.loader.mjs), but in your repro it’s just a good oldnode. It shouldn’t make a difference, but perhaps Node regressed and is somehow registering the loaders twice even when they have the same path? Investigating.I was able to fix this issue in my project by downgrading eslint-plugin-prettier to v5.3.1 from v5.4.0 (also affected is v5.4.1): https://github.com/retrixe/IveBot/commit/4550fecf2a96c52606e91a411a4d8b51bbea71f5
This suggests to me the bug was introduced (reintroduced?) by some behavioural change caused by https://github.com/prettier/eslint-plugin-prettier/commit/59a0cae5f27801d7e00f257c6be059a848b32fbe (the only commit in v5.4.0)
This is still an issue as of 0.11.0.
Repro:
yarn lintand observe various lint errorsThen update the
nodeLinkersetting:and run
yarnagain, restart VSCode, observe squiggly lines in failing files.@agarwalvaibhav0211 yes it has been fixed with latest release of
synckit(https://github.com/un-ts/synckit/releases/tag/v0.9.1) which is a dependency ofeslint-plugin-prettier. Just make sure you have synckit@0.9.1 in your packages. If reinstallingeslint-plugin-prettierpackage doesn’t fetch latestsynckitthen you can enforce it through yarnresolutions like this:@sheldonmaschmeyer right, it wasn’t posed as a solution, but as a demonstration that the fault is with the pnp linker