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

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@eslint/js' #1850

Closed
CaseyHofland opened this issue May 29, 2024 · 4 comments
Closed

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@eslint/js' #1850

CaseyHofland opened this issue May 29, 2024 · 4 comments

Comments

@CaseyHofland
Copy link

CaseyHofland commented May 29, 2024

Hi there, I've been trying to set up eslint in our workspaces, and I can confirm that eslint has been correctly installed and configured: running yarn eslint src/**/*.vue for example runs as expected. We are having trouble getting the vscode-eslint extension to work with yarn.

On startup, we are seeing the following error in the ESLint Output tab (Ctrl + Shift + U on any vue or js file):

[Info  - 1:54:23 PM] ESLint server is starting.
[Info  - 1:54:23 PM] ESLint server running in node v18.18.2
[Info  - 1:54:23 PM] ESLint server is running.
[Info  - 1:54:26 PM] ESLint library loaded from: P:\M*************\frontend\.yarn\sdks\eslint\lib\unsupported-api.js
Uncaught exception received.
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@eslint/js' imported from P:\M*************\frontend\eslint.config.js
Did you mean to import @eslint-js-npm-9.3.0-de76de965f-5af317c8bc.zip/node_modules/@eslint/js/src/index.js?
    at new NodeError (node:internal/errors:405:5)
    at packageResolve (node:internal/modules/esm/resolve:863:9)
    at moduleResolve (node:internal/modules/esm/resolve:912:20)
    at defaultResolve (node:internal/modules/esm/resolve:1105:11)
    at nextResolve (node:internal/modules/esm/loader:166:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:840:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:429:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
    at link (node:internal/modules/esm/module_job:76:36)
Uncaught exception received.
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@eslint/js' imported from P:\M*************\frontend\eslint.config.js
Did you mean to import @eslint-js-npm-9.3.0-de76de965f-5af317c8bc.zip/node_modules/@eslint/js/src/index.js?
    at new NodeError (node:internal/errors:405:5)
    at packageResolve (node:internal/modules/esm/resolve:863:9)
    at moduleResolve (node:internal/modules/esm/resolve:912:20)
    at defaultResolve (node:internal/modules/esm/resolve:1105:11)
    at nextResolve (node:internal/modules/esm/loader:166:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:840:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:429:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
    at link (node:internal/modules/esm/module_job:76:36)
Uncaught exception received.
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@eslint/js' imported from P:\M*************\frontend\eslint.config.js
Did you mean to import @eslint-js-npm-9.3.0-de76de965f-5af317c8bc.zip/node_modules/@eslint/js/src/index.js?
    at new NodeError (node:internal/errors:405:5)
    at packageResolve (node:internal/modules/esm/resolve:863:9)
    at moduleResolve (node:internal/modules/esm/resolve:912:20)
    at defaultResolve (node:internal/modules/esm/resolve:1105:11)
    at nextResolve (node:internal/modules/esm/loader:166:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:840:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:429:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
    at link (node:internal/modules/esm/module_job:76:36)
Uncaught exception received.
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@eslint/js' imported from P:\M*************\frontend\eslint.config.js
Did you mean to import @eslint-js-npm-9.3.0-de76de965f-5af317c8bc.zip/node_modules/@eslint/js/src/index.js?
    at new NodeError (node:internal/errors:405:5)
    at packageResolve (node:internal/modules/esm/resolve:863:9)
    at moduleResolve (node:internal/modules/esm/resolve:912:20)
    at defaultResolve (node:internal/modules/esm/resolve:1105:11)
    at nextResolve (node:internal/modules/esm/loader:166:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:840:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:429:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
    at link (node:internal/modules/esm/module_job:76:36)

Expected Behaviour

Eslint server starting up correctly via yarn, and listing problems in the vscode Problems tab.

Reproduce

  • Run the following commands:

yarn add -D eslint@8.56.0 < this is necessary for @typescript-eslint/parser which does not support version 9.x
yarn add -D @eslint/js typescript-eslint eslint-plugin-vue vue-eslint-parser @typescript-eslint/parser
yarn install

  • Place the following eslint.config.js file in the root folder:
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
import pluginVue from "eslint-plugin-vue";
import vueParser from 'vue-eslint-parser';
import typescriptParser from '@typescript-eslint/parser';

export default [
  pluginJs.configs.recommended,
  ...tseslint.configs.recommended,
  ...pluginVue.configs["flat/recommended"],
  {
    languageOptions: {
      parser: vueParser,
      parserOptions: {
          parser: typescriptParser,
          sourceType: "module",
      },
    },
    rules: {
      // override/add rules settings here
      'vue/multi-word-component-names': 'off',
      semi: "warn",
      "prefer-const": "warn",
    },
  },
];
  • Add the following in your settings.json:
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    "typescript",
    "typescriptreact",
    "html",
    "vue"
  ],

Of Note

  • Running yarn install or yarn dlx @yarnpkg/sdks does not fix this issue, even though both of these commands complete without errors.
  • If we run npm install, then the ESLint extension works properly, because it can find all related packages. We refuse however to use npm in our projects for the amount of overhead it produces.
  • Whilst the error shows only one package as the culprit, changing the order of packages in the eslint.config.js file shows that placing any package at the top will default it as the culprit for the error.
@dbaeumer
Copy link
Member

This is caused by a problem in yarn dlx. For the details see: yarnpkg/berry#6219

As soon as they have fixed this and released a new version I will ship an updated version of the extension to make this scenario work.

@joonaathaan
Copy link

Any updates regarding this?

@dbaeumer
Copy link
Member

3.0.10 and a new version of yarn is out which should make this work.

@CaseyHofland
Copy link
Author

Any updates regarding this?

I can confirm that upgrading to the latest yarn and running yarn dlx @yarnpkg/sdks vscode solved my issue. Very happy that it was just a fluke!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants