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: Failed to load plugin '*' declared in 'BaseConfig... #546

Open
AndrewMSHowe opened this issue May 11, 2021 · 22 comments · May be fixed by #589
Open

Error: Failed to load plugin '*' declared in 'BaseConfig... #546

AndrewMSHowe opened this issue May 11, 2021 · 22 comments · May be fixed by #589

Comments

@AndrewMSHowe
Copy link

AndrewMSHowe commented May 11, 2021

With 0.40.1, xo --help works. But in my project folder, xo gives:
Error: Failed to load plugin 'ava' declared in 'BaseConfig » /usr/lib/node_modules/xo/config/plugins.js': Cannot find module 'eslint-plugin-ava'

npm list -g --depth 1 gives (for xo):

└─┬ xo@0.40.1
  ├── @eslint/eslintrc@0.4.1
  ├── @typescript-eslint/eslint-plugin@4.23.0
  ├── @typescript-eslint/parser@4.23.0
  ├── arrify@2.0.1
  ├── cosmiconfig@7.0.0
  ├── debug@4.3.1
  ├── define-lazy-prop@2.0.0
  ├── eslint-config-prettier@8.3.0
  ├── eslint-config-xo-typescript@0.41.1
  ├── eslint-config-xo@0.36.0
  ├── eslint-formatter-pretty@4.0.0
  ├── eslint-import-resolver-webpack@0.13.0
  ├── eslint-plugin-ava@12.0.0
  ├── eslint-plugin-eslint-comments@3.2.0
  ├── eslint-plugin-import@2.22.1
  ├── eslint-plugin-no-use-extend-native@0.5.0
  ├── eslint-plugin-node@11.1.0
  ├── eslint-plugin-prettier@3.4.0
  ├── eslint-plugin-promise@5.1.0
  ├── eslint-plugin-unicorn@32.0.1
  ├── eslint@7.26.0
  ├── find-cache-dir@3.3.1
  ├── find-up@5.0.0
  ├── fs-extra@10.0.0
  ├── get-stdin@8.0.0
  ├── globby@9.2.0
  ├── has-flag@4.0.0
  ├── imurmurhash@0.1.4
  ├── is-path-inside@3.0.3
  ├── json-stable-stringify-without-jsonify@1.0.1
  ├── json5@2.2.0
  ├── lodash@4.17.21
  ├── meow@9.0.0
  ├── micromatch@4.0.4
  ├── open-editor@3.0.0
  ├── p-filter@2.1.0
  ├── p-map@4.0.0
  ├── p-reduce@2.1.0
  ├── path-exists@4.0.0
  ├── prettier@2.3.0
  ├── resolve-cwd@3.0.0
  ├── semver@7.3.5
  ├── slash@3.0.0
  ├── to-absolute-glob@2.0.2
  ├── typescript@4.2.4
  └── update-notifier@5.1.0

So eslint-plugin-ava is there, but something isn't working.

Require stack:
- <...>/__placeholder__.js
Referenced from: /usr/lib/node_modules/xo/config/plugins.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
    at Function.resolve (internal/modules/cjs/helpers.js:80:19)
    at Object.resolve (/usr/lib/node_modules/xo/node_modules/@eslint/eslintrc/lib/shared/relative-module-resolver.js:28:50)
    at ConfigArrayFactory._loadPlugin (/usr/lib/node_modules/xo/node_modules/@eslint/eslintrc/lib/config-array-factory.js:1017:39)
    at ConfigArrayFactory._loadExtendedPluginConfig (/usr/lib/node_modules/xo/node_modules/@eslint/eslintrc/lib/config-array-factory.js:837:29)
    at ConfigArrayFactory._loadExtends (/usr/lib/node_modules/xo/node_modules/@eslint/eslintrc/lib/config-array-factory.js:779:29)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (/usr/lib/node_modules/xo/node_modules/@eslint/eslintrc/lib/config-array-factory.js:720:25)
    at _normalizeObjectConfigDataBody.next (<anonymous>)
    at ConfigArrayFactory._normalizeObjectConfigData (/usr/lib/node_modules/xo/node_modules/@eslint/eslintrc/lib/config-array-factory.js:665:20)
    at _normalizeObjectConfigData.next (<anonymous>)

Originally posted by @AndrewMSHowe in #543 (comment)

@sindresorhus
Copy link
Member

// @Richienb

@Richienb
Copy link
Contributor

Richienb commented May 12, 2021

There's no way to provide the absolute path of a plugin so I'm not quite sure how to fix it. The issue appears to have been present before xo 0.40.0 but Error: Failed to load config "xo" to extend from. would be thrown before it had a chance to be handled.

Perhaps it could be possible to set the cwd to a directory that can resolve the plugins and then compute the absolute paths of everything else but that would be opening a can of worms.

eslint/eslint#6237

@AndrewMSHowe
Copy link
Author

Is this happening because I'm installing xo globally? I'm sorry to report these problems :( I already have an eslint setup in my project directory so I thought installing xo globally (like in the docs) would allow me to try it.

@Richienb
Copy link
Contributor

Is this happening because I'm installing xo globally?

It is very likely the case. Try a local installation and see if it works.

@SiddharthShyniben
Copy link

I had this problem and a local install of xo fixed it

@AndrewMSHowe
Copy link
Author

I'll try it, it's just that I already have eslint and some plugins installed, and I'm worried that something's going to get messed up :(

@sindresorhus
Copy link
Member

@AndrewMSHowe Can you try running $ npx xo in your project?

@sindresorhus
Copy link
Member

@Richienb Maybe we could detect this case and add a human-friendly error message?

@AndrewMSHowe
Copy link
Author

OK weird so that asked me to install xo, and it has apparently put it somewhere other than global or in my project. It doesn't work because of some docker stuff that's mapped into my project folder. I would have to find a way around that. If I run it from a subdir with just source, it gives the same error about plugin 'ava' (I'm not using ava, but I guess it wants to load the plugin anyway). This time the error is Error: Failed to load plugin 'ava' declared in 'BaseConfig » /home/andrew/.npm/_npx/5b73490bd3e0c08a/node_modules/xo/config/plugins.js': Cannot find module 'eslint-plugin-ava' so I guess ~/.npm/_npx is where it ended up.
If you add an error message for global and npx usage then you will want to remove the --global from the Install section in the readme.md...

@AndrewMSHowe
Copy link
Author

Sorry I guess I need "npx xo" for local usage when I have installed xo locally rather than letting npx install it in its own stash, so that may have been misleading above.

@AndrewMSHowe
Copy link
Author

Anyway it does work locally, although I'm not sure how I will get it to work automatically in VSCode as well as my current setup.

@Richienb
Copy link
Contributor

Just discovered the resolvePluginsRelativeTo option which should be able to fix this. PR incoming soon.

@AndrewMSHowe
Copy link
Author

AndrewMSHowe commented Jun 18, 2021

<gentle nudge> this stuff is also holding up the vscode plugin. Did you get anywhere with your PR?

@Richienb
Copy link
Contributor

As it turns out, fixing this problem causes another one to occur which has led me to conclude that resolvePluginsRelativeTo is not the solution.

@sindresorhus
Copy link
Member

Would you be able to elaborate what other problem it causes? For posterity.

@Richienb
Copy link
Contributor

The option doesn't let you specify multiple directories to resolve plugins from so that it would be possible to specify the node_modules where xo is installed and the node_modules of the current working directory at the same time.

Because it is also not possible to provide absolute paths as plugins, I don't see any good way to do this.

@sindresorhus
Copy link
Member

@Richienb Thanks for elaborating. It's seems we have hit a dead-end... Maybe it's worth opening an ESLint issue with a proposal with an option/API that could resolve this issue.

@Richienb
Copy link
Contributor

eslint/eslint#6237

@fisker fisker linked a pull request Aug 8, 2021 that will close this issue
@fisker
Copy link
Contributor

fisker commented Aug 8, 2021

@Richienb I didn't see you comment above before I send #589, can you explain what case won't work with the resolvePluginsRelativeTo option?

@fisker
Copy link
Contributor

fisker commented Aug 8, 2021

Did you mean install xo in a parent dir and install another plugin in a child dir, and run from child dir?

@Richienb
Copy link
Contributor

Richienb commented Aug 8, 2021

@Richienb I didn't see you comment above before I send #589, can you explain what case won't work with the resolvePluginsRelativeTo option?

When xo could still be installed globally, it was not possible to reference plugins from both the node_modules of xo and the node_modules of the project at hand. However, since xo removed global installation support, this might no longer be a problem.

@fisker
Copy link
Contributor

fisker commented Aug 9, 2021

Right, thanks.

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

Successfully merging a pull request may close this issue.

6 participants