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

Failed to load plugin in configuration #2481

Open
4 tasks
jdbruijn opened this issue Mar 1, 2021 · 3 comments
Open
4 tasks

Failed to load plugin in configuration #2481

jdbruijn opened this issue Mar 1, 2021 · 3 comments

Comments

@jdbruijn
Copy link
Contributor

jdbruijn commented Mar 1, 2021

Expected Behavior

I'd expect it to load the plugin as it did previously. I'm not sure what changed between now and 'previously', whether that is node/npm version or something else.

Current Behavior

Loading a plugin of a configuration fails.

Edit: It the plugin is found as expected when I install @commitlint/[email protected] instead of 12.0.0 or 12.0.1, so it seems to me this bug was introduced in 12.0.0. The two suspects in that release, based on the changelog would IMO be #2070 and #982, where the former is IMHO most likely.

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

What works, but is very undesired, is installing the plugin manually as user of my configuration.

Steps to Reproduce (for bugs)

  1. Create an empty workspace mkdir test && cd test
  2. Install @commitlint/cli and @vidavidorra/commitlint-config
    npm i -D @commitlint/[email protected] @vidavidorra/[email protected]
  3. Create a configuration
    echo "module.exports = { extends: ['@vidavidorra/commitlint-config'] };" > commitlint.config.js
  4. Test a commit message
    $ echo 'test (fail)' | npx --no-install commitlint
    Failed to load plugin commitlint-plugin-function-rules.
    /home/jdebruijn/projects/node_modules/@commitlint/cli/lib/cli.js:106
            throw err;
            ^
    
    MissingPluginError: Failed to load plugin function-rules: Cannot find module 'commitlint-plugin-function-rules'
    Require stack:
    - /home/jdebruijn/projects/node_modules/@commitlint/load/lib/utils/load-plugin.js
    - /home/jdebruijn/projects/node_modules/@commitlint/load/lib/load.js
    - /home/jdebruijn/projects/node_modules/@commitlint/cli/lib/cli.js
    - /home/jdebruijn/projects/node_modules/@commitlint/cli/cli.js
        at Object.loadPlugin [as default] (/home/jdebruijn/projects/node_modules/@commitlint/load/lib/utils/load-plugin.js:32:23)
        at /home/jdebruijn/projects/node_modules/@commitlint/load/lib/load.js:66:38
        at Array.forEach (<anonymous>)
        at Object.load [as default] (/home/jdebruijn/projects/node_modules/@commitlint/load/lib/load.js:64:24)
        at processTicksAndRejections (node:internal/process/task_queues:94:5)
        at async main (/home/jdebruijn/projects/node_modules/@commitlint/cli/lib/cli.js:140:20) {
      messageTemplate: 'plugin-missing',
      messageData: {
        pluginName: 'commitlint-plugin-function-rules',
        commitlintPath: '/home/jdebruijn/projects/node_modules/@commitlint/load'
      }
    }
commitlint.config.js
module.exports = {
  extends: ['@vidavidorra/commitlint-config'],
};

Context

I have a shared configuration, @vidavidorra/commitlint-config, which uses a plugin, commitlint-plugin-function-rules as plugin. In my configuration I have the plugin as npm dependency. In my configuration I use this plugin to create certain rules. Users of my configuration get an error about the plugin of my configuration not being found, where users only install @vidavidorra/commitlint-config and not its dependencies, which they shouldn't need to care about.

Your Environment

Executable Version
commitlint --version 12.0.1
git --version 2.30.1
node --version 15.10.0
@jdbruijn
Copy link
Contributor Author

jdbruijn commented Mar 1, 2021

Well, it doesn't seems to be #2070. I've reverted the changes in node_modules/@commitlint/resolve-extends/lib/index.js, but am still getting the same issue on CLI 12.0.0 and @vidavidorra/[email protected].

@jdbruijn
Copy link
Contributor Author

jdbruijn commented Mar 1, 2021

Okay, so this is very strange. I honestly have no idea what is going on. 1-3 are when the plugin is found and I can normally run commitlint and 4-6 when the plugin is not found and commitlint fails.

  1. My devDependencies has @commitlint/cli 11.0.0 in package.json.
  2. I run rm -rf node_modules package-lock.json && npm i.
  3. There is a node_modules/commitlint-plugin-function-rules directory with my plugin content.
    The node_modules/@vidavidorra/commitlint-config directory has no nested node_modules directory.
  4. I change @commitlint/cli to 12.0.0 in package.json.
  5. I run rm -rf node_modules package-lock.json && npm i.
  6. There is no node_modules/commitlint-plugin-function-rules directory.
    The node_modules/@vidavidorra/commitlint-config directory has a nested node_modules directory with o.a. a commitlint-plugin-function-rules directory with my plugin content.

@jdbruijn
Copy link
Contributor Author

jdbruijn commented Mar 2, 2021

It seems this issue comes up when a plugin uses a different commitlint version (major at least, not sure about whether minor and patch matter) then the configuration and/or user CLI. My plugin now uses the same version as my configuration and on commitlint CLI 12.0.0 runs as expected.

With this and my previous findings in mind, I'd say the issue is how commitlint resolves plugins and/or configurations. Specifically it seems to depend on npm flattening the dependency tree, which I believe is not guaranteed to happen but I'm no expert. Perhaps someone with more experience can shed more light on this topic and issue?

As I can easily make my plugin and config use the same version, this isn't much of an issue for me so I probably won't be diving deeper into this issue although I think my findings already show some detail and possibly the cause of the issue. Of course I'd still be happy to help provide more information or doing some tests/reproduction if needed.

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

No branches or pull requests

1 participant