less / less/less.js

Plugin loading fails when using syncImport

Open
#3,294 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
17k
Forks
3.4k
Avg merge
7h 42m
Merged PRs (30d)
26

Description

Loading a plugin fails when less is using the syncImport option. The File manager seems to return the result instead of a promise in this case. It can be easily reproduced with the following code:

Example:

// pi.js
module.exports = {
    install: function(less, pluginManager, functions) {
        functions.add('pi', function() {
            return Math.PI;
        });
    }
};
// index.js
var less = require('less');

less.render('@plugin "./pi.js"; @var pi()', { syncImport: true }, function (error, output) {
    console.log(error, output);
});

Error:

TypeError: fileManager.loadFile(...).then is not a function
    at /home/ydelange/less-bug/node_modules/less/lib/less-node/plugin-loader.js:34:72
    at new Promise (<anonymous>)
    at PluginLoader.loadPlugin (/home/ydelange/less-bug/node_modules/less/lib/less-node/plugin-loader.js:33:12)
    at ImportManager.push (/home/ydelange/less-bug/node_modules/less/lib/less/import-manager.js:149:36)
    at ImportVisitor.processImportNode (/home/ydelange/less-bug/node_modules/less/lib/less/visitors/import-visitor.js:88:28)
    at ImportVisitor.visitImport (/home/ydelange/less-bug/node_modules/less/lib/less/visitors/import-visitor.js:50:22)
    at Visitor.visit (/home/ydelange/less-bug/node_modules/less/lib/less/visitors/visitor.js:76:32)
    at Visitor.visitArray (/home/ydelange/less-bug/node_modules/less/lib/less/visitors/visitor.js:102:22)
    at Ruleset.accept (/home/ydelange/less-bug/node_modules/less/lib/less/tree/ruleset.js:40:30)
    at Visitor.visit (/home/ydelange/less-bug/node_modules/less/lib/less/visitors/visitor.js:83:18)

Code that is causing it:
https://github.com/less/less.js/blob/master/lib/less-node/file-manager.js#L42

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the syncImport reproduction in index.js and inspect the linked code in lib/less-node/file-manager.js alongside the failing call in lib/less-node/plugin-loader.js. Run the example with the pi.js plugin and confirm that loading no longer raises the .then TypeError and the render callback receives its result.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.