Failed to load parser '@typescript-eslint/parser'
Hi!
I have troubles with setting up ESLint for my project. This does not seem to be an issue with PHPStorm itself, since I am getting the same error with CLI as well (at least when I use --resolve-plugins-relative-to), but maybe someone here can help me?
My node setup is outside the project directory, since I only use it for TypeScript, Terser and now am trying to use it for ESLint. I've installed ESLint both globally and with --save-dev, created a config file as described in this article, but ESLint still fails with:
Error: Failed to load parser '@typescript-eslint/parser' declared in '--config': Cannot find module '@typescript-eslint/parser'
Require stack:
- C:\Users\simbi\OneDrive\Documents\!Personal\Coding\WebServer\htdocs\js\.eslintrc
Error: Failed to load parser '@typescript-eslint/parser' declared in '--config': Cannot find module '@typescript-eslint/parser'
Require stack:
- C:\Users\simbi\OneDrive\Documents\!Personal\Coding\WebServer\htdocs\js\.eslintrc
at Module._resolveFilename (node:internal/modules/cjs/loader:946:15)
at Function.resolve (node:internal/modules/cjs/helpers:108:19)
at Object.resolve (C:\Users\simbi\OneDrive\Documents\!Personal\Coding\WebServer\node\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:2325:46)
at ConfigArrayFactory._loadParser (C:\Users\simbi\OneDrive\Documents\!Personal\Coding\WebServer\node\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:3304:39)
at ConfigArrayFactory._normalizeObjectConfigDataBody (C:\Users\simbi\OneDrive\Documents\!Personal\Coding\WebServer\node\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:3078:43)
at _normalizeObjectConfigDataBody.next (<anonymous>)
at ConfigArrayFactory._normalizeObjectConfigData (C:\Users\simbi\OneDrive\Documents\!Personal\Coding\WebServer\node\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:3019:20)
at _normalizeObjectConfigData.next (<anonymous>)
at ConfigArrayFactory.loadFile (C:\Users\simbi\OneDrive\Documents\!Personal\Coding\WebServer\node\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:2829:16)
at createCLIConfigArray (C:\Users\simbi\OneDrive\Documents\!Personal\Coding\WebServer\node\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:3637:35)
Process finished with exit code -1
Here are my settings
The "htdocs" directory is the project directory.
When I try to run ESLint in CLI like
npx eslint --config "C:\Users\simbi\OneDrive\Documents\!Personal\Coding\WebServer\htdocs\js\.eslintrc" "C:\Users\simbi\OneDrive\Documents\!Personal\Coding\WebServer\htdocs\js\Common\Url.ts"
I get this:
ESLint couldn't find the plugin "@typescript-eslint/eslint-plugin".
(The package "@typescript-eslint/eslint-plugin" was not found when loaded as a Node module from the directory "C:\Users\simbi\OneDrive\Documents\!Personal\Coding\WebServer\htdocs\js".)
It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:
npm install @typescript-eslint/eslint-plugin@latest --save-dev
The plugin "@typescript-eslint/eslint-plugin" was referenced from the config file in "--config".
If I use --resolve-plugins-relative-to with seemingly anything - I get the same thing as in PHPStorm.
I search for similar problems, but was not able to find anything, that would work. Besides most of the threads I've found about this just suggest updating either node or ESLint, but I am already on latest versions.
Does anyone have an idea, what I can try to solve this?
Thank you.
Please sign in to leave a comment.
ESLint plugins and parsers are resolved relative to the configuration file. In other words, ESLint loads the plugin as a user would obtain by running
require('eslint-plugin-pluginname')
in the config file, i.e. the Node.js modules resolution rules are used (https://nodejs.org/api/modules.html#loading-from-node_modules-folders): the folders hierarchy is traversed up to the system root looking fornode_modules
.But the issue is that
Coding\WebServer\node\
folder is a sibling ofCoding\WebServer\htdocs\
folder, so thenode_modules
in it are not found when attempting to traverse the hierarchy, and the modules can't be loaded. Solution is obvious: you need to make sure to install node modules in your project root and not in a certain subfolder to make modules resolution workBut should not `--resolve-plugins-relative-to` then solve it?
Not sure if it's supposed to work in such cases. But, if it doesn't work for you in terminal, it's not a problem that can be fixed on IDE end
Looks like it does work, when I use "Coding\WebServer\node\package.json" for path to config. Downside is that config is not in the project, though.
I thought I could avoid duplicating stuff in project folder, but looks like copying package.json and `npm install` is the easiest solution