Skip to content

"plugin.install is not a function" when trying to add plugins to node script #2915

Closed

Description

@josh18

Trying to get less working from a node script but I get this error message when trying to add a plugin.

.../npm-scripts/node_modules/less/lib/less/plugin-manager.js:29
    plugin.install(this.less, this);
           ^

TypeError: plugin.install is not a function
    at PluginManager.addPlugin (.../npm-scripts/node_modules/less/lib/less/plugin-manager.js:29:12)
    at PluginManager.addPlugins (.../npm-scripts/node_modules/less/lib/less/plugin-manager.js:19:18)
    at Object.parse (.../npm-scripts/node_modules/less/lib/less/parse.js:34:27)
    at Object.render (.../npm-scripts/node_modules/less/lib/less/render.js:25:18)
    at .../npm-scripts/less-watch.js:27:14
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:405:3)

Tried with less-plugin-autoprefix and with less-plugin-clean-css. Any idea what could be causing this? I'm not doing anything strange (that I know of), my code is pretty much just:

var lessOptions = {
    plugins: [lessAutoPrefix]
};

less.render(data, lessOptions, function(error, output) {
    // do stuff
});

Without the plugins option everything works fine. It also works fine when doing the same thing from the command line. Just installed all the modules so everything should be up to date.

Activity

  1. seven-phases-max commented on Jun 29, 2016

    @seven-phases-max
    Member

    See the correct plugin instantiation examples in their docs. I.e.:

    var lessOptions = {
        plugins: [new lessAutoPrefix()]
    };
    
    less.render(data, lessOptions, function(error, output) {
        // do stuff
    });
    

    I.e. usually (actually for all plugins I know) you pass an instance/object of the plugin "class" (not the class itself).


    Selfnote: probably the example needs a correction since it could be misleading (another example of the same confusion).

  2. seven-phases-max commented on Jun 29, 2016

    @seven-phases-max
    Member

    Closing as not an issue.

  3. matthew-dean commented on Jun 29, 2016

    @matthew-dean
    Member

    @seven-phases-max I would say that based on the plugin documentation, plugins are actually not (strictly) following what Less is supporting, which is that a plugin returns an object with a certain signature, and not a function that can produce said object.

    So I wouldn't say the example needs to be updated so much as the plugins need to be updated, as they're not returning a properly formed object with required properties. They're returning a function.

  4. matthew-dean commented on Jun 29, 2016

    @matthew-dean
    Member

    It might be reasonable for Less to attempt to create an instance if a function is returned, but I would still say that it's the plugin's responsibility to return a proper object signature when require'd.

  5. josh18 commented on Jun 29, 2016

    @josh18
    Author

    Oh that makes sense, thanks! Yeah it was that documentation that confused me.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions