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

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

Closed
josh18 opened this issue Jun 27, 2016 · 5 comments
Closed

Comments

@josh18
Copy link

josh18 commented Jun 27, 2016

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.

@seven-phases-max
Copy link
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).

@seven-phases-max
Copy link
Member

Closing as not an issue.

@matthew-dean
Copy link
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.

@matthew-dean
Copy link
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.

@josh18
Copy link
Author

josh18 commented Jun 29, 2016

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants