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?]: ESLint extension doesn't work with yarn pnp - Error: Missing "./lib/api.js" export in "eslint" package #3578

Closed
1 task
NixBiks opened this issue Oct 15, 2021 · 7 comments · Fixed by #3709
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@NixBiks
Copy link

NixBiks commented Oct 15, 2021

Self-service

  • I'd be willing to implement a fix

Describe the bug

I'm using the ESLint extension in VSCode. Unfortunately it doesn't work with Plug'n'Play - according to the docs it should work if I understand correctly?

I've been looking at issues both here and in the ESLint extension repro but I haven't found anyone with this exact error it seems. I'm not sure if the issue belongs here or in the ESLint extension repro, let me know.

To reproduce

Make sure you have arcanis.vscode-zipfs and dbaeumer.vscode-eslint extensions installed in VS Code.

Run the following commands and just select defaults in the config initialization wizard

mkdir eslint-test
cd eslint-test
yarn set version berry
yarn init
yarn add -D eslint
yarn dlx @yarnpkg/sdks vscode
yarn eslint --init

Now verify that eslint will highlight an error in .eslintrc.js when running the following command (as expected)

yarn eslint .

Open eslintrc.js in VS Code and verify that the ESLint extension doesn't work. You can select the Output tab and select ESLint in the dropdown and see the following error

[Error - 2:16:22 PM] Error: Missing "./lib/api.js" export in "eslint" package
Require stack:
- /home/nixd/Projects/eslint-test/.pnp.cjs
    at bail (/home/nixd/Projects/eslint-test/.pnp.cjs:10700:8)
    at resolve (/home/nixd/Projects/eslint-test/.pnp.cjs:10776:10)
    at applyNodeExportsResolution (/home/nixd/Projects/eslint-test/.pnp.cjs:11027:28)
    at resolveUnqualifiedExport (/home/nixd/Projects/eslint-test/.pnp.cjs:11540:35)
    at resolveRequest (/home/nixd/Projects/eslint-test/.pnp.cjs:11606:99)
    at Object.resolveRequest (/home/nixd/Projects/eslint-test/.pnp.cjs:11681:26)
    at Function.external_module_.Module._resolveFilename (/home/nixd/Projects/eslint-test/.pnp.cjs:10533:34)
    at Function.external_module_.Module._load (/home/nixd/Projects/eslint-test/.pnp.cjs:10355:48)
    at Module.require (internal/modules/cjs/loader.js:1006:19)
    at require (internal/modules/cjs/helpers.js:88:18)
[Error - 2:20:20 PM] Error: Missing "./lib/api.js" export in "eslint" package

Environment

System:
    OS: Linux 5.11 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: (24) x64 AMD Ryzen 9 3900X 12-Core Processor
  Binaries:
    Node: 15.14.0 - /tmp/xfs-affdb263/node
    Yarn: 3.0.2 - /tmp/xfs-affdb263/yarn
    npm: 7.24.1 - ~/.nvm/versions/node/v15.14.0/bin/npm

Additional context

No response

@NixBiks NixBiks added the bug Something isn't working label Oct 15, 2021
@joelmukuthu
Copy link

Hi @mr-bjerre I just experienced the same issue. This is specifically an error with ESLint v8 and is caused by https://eslint.org/docs/8.0.0/user-guide/migrating-to-8.0.0#the-lib-entrypoint-has-been-removed.

Before it's fixed here, you can workaround it by updating your ESLint SDK file (.yarn/sdks/eslint/lib/api.js). Change the export from:

// Defer to the real eslint your application uses
module.exports = absRequire(`eslint/lib/api.js`);

To:

// Defer to the real eslint your application uses
module.exports = absRequire(`eslint`);

@NixBiks NixBiks closed this as completed Oct 15, 2021
@NixBiks NixBiks reopened this Oct 15, 2021
@NixBiks
Copy link
Author

NixBiks commented Oct 15, 2021

Cool @joelmukuthu .

I agree that the workaround doesn't throw the error anymore but the extension doesn't seem to highlight any issues either. So it isn't really working...

EDIT

This is related to microsoft/vscode-eslint#1225

@arcanis arcanis added the good first issue Good for newcomers label Oct 18, 2021
@arcanis
Copy link
Member

arcanis commented Oct 18, 2021

Hm but why is vscode-eslint reading in ./lib/api.js? I don't find which part of the extension does it 🤔

@joelmukuthu
Copy link

@arcanis it seems that OP ran into a different issue that's related to vscode-eslint :)

The original issue is caused by code in the ESLint SDKs for VS Code that are generated by Yarn. I'm not sure but it looks like this is what causes it:

`lib/api.js` as PortablePath,

Perhaps changing that to an empty string would fix it? 😃 And not to complicate this, but it might also be worthwhile to update how the SDKs are generated; in essence, to remove direct imports of "internal" module files

@vinassefranche
Copy link
Contributor

Hello! I see this has the label good first issue I'd be willing to work on it to understand better how this work and help fix this issue. I have no idea how the sdk code is generated though. Is there any documentation available to start looking at this on my own? Are there any hint on where to start digging?

Thanks in advance for your answers!

@merceyz merceyz mentioned this issue Nov 10, 2021
3 tasks
@merceyz
Copy link
Member

merceyz commented Nov 10, 2021

This was fixed in #3709 but we forgot to reference this issue

yarn dlx @yarnpkg/sdks

@merceyz merceyz closed this as completed Nov 10, 2021
@vinassefranche
Copy link
Contributor

@merceyz thanks for the info! Don't hesitate to ping me if you see something I can help on!

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

Successfully merging a pull request may close this issue.

5 participants