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

Can't load plugins when used in Visual Studio #29

Open
andyrooger opened this issue Mar 26, 2020 · 5 comments
Open

Can't load plugins when used in Visual Studio #29

andyrooger opened this issue Mar 26, 2020 · 5 comments

Comments

@andyrooger
Copy link

andyrooger commented Mar 26, 2020

If any plugins are specified in the .eslintrc.js then typescript-eslint-language-service fails to load.

module.exports = {
    root: true,
    parser: '@typescript-eslint/parser',
    parserOptions: {
        tsconfigRootDir: __dirname,
        project: ['./tsconfig.json'],
        sourceType: 'module'
    },
    plugins: [
        '@typescript-eslint',
    ],
    extends: [],
    rules: {
        '@typescript-eslint/no-unused-vars': ['error'],
    }
};

In the TSS logs I see the following output:

Info 4136 [18:25:57.648] [typescript-eslint-language-service] Failed to load plugin '@typescript-eslint' declared in '....\src\myproject.eslintrc.js': Cannot find module '@typescript-eslint/eslint-plugin'
Require stack:
- C:\WINDOWS\system32\__placeholder__.js

  • os: Windows 10
  • eslint: 6.8.0
  • typescript-eslint-language-service: 2.1.8
@andyrooger
Copy link
Author

I've been experimenting - seems to be the problem is that on Visual Studio the cwd is set to C:\WINDOWS\system32 when this gets run.

CascadingConfigArrayFactory and Linter both have options object that can be passed with a cwd to use. If I set that to something sensible and temporarily process.chdir(...) for the duration of getESLintResult then I can get this working.

CLIEngine also has a cwd you can pass but it seems to make things worse...

I think this should be testable outside of VS by just doing a process.chdir to something silly when the plugin is starting.

@andyrooger
Copy link
Author

For now I'm working around this with a plugin that looks like

function init(modules) {
    process.chdir('<project root>');

    function create(info) {
        return info.languageService;
    }
    return { create };
}

module.exports = init;

If I load it right before typescript-eslint-language-service then I can get the plugin loaded and working successfully. It's obviously not a great permanent solution though.

@laduke
Copy link

laduke commented Apr 21, 2023

I seeing something similar on macos. I don't use visual studio code, but I wanted to make sure repo/set up worked for people that do. It's 3 years later, so probably a different issue. How did no one else run into this? Are we doing something weird in our eslintrc?

Info 26   [09:16:07.651] Failed to load module 'typescript-eslint-language-service' from /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/node_modules: Error: Could not resolve JS module 'typescript-eslint-language-service' starting at '/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/node_modules'
....
/Applications/node_modules/
...
/node_modules/typescript-eslint-language-service/index.jsx

Why is it trying to load stuff from /Applications/Visual Studio ? and from /node_modules?

typescript-eslint/typescript-eslint#6883

@andyrooger
Copy link
Author

If it is the same problem you can try https://www.npmjs.com/package/vs-compat-ts-plugin - it's how I've been solving the initial problem for a few years.

Contains the code above with a few extra pieces. Though I don't recognise your errors.

@laduke
Copy link

laduke commented Apr 21, 2023

Thanks for responding.
Sadly, now it's trying to load vs-compat-ts-plugin from the same wrong places. Was worth a try.

Oops. I'm testing in Visual Studio CODE, wrong issue.

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

2 participants