xojs/xo

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

Opened this issue · 22 comments

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)

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

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.

Is this happening because I'm installing xo globally?

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

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

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 :(

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

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

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...

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.

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.

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

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

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

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

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.

@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 I didn't see you comment above before I send #589, can you explain what case won't work with the resolvePluginsRelativeTo option?

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

@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.

Right, thanks.