A
A
Alexander2017-10-17 17:24:57
css
Alexander, 2017-10-17 17:24:57

Node.js and less, module connection error, what's the problem?

1) Installed Less: npm install -g less In the less console, everything works fine.
2) I write the following code:
var less = require.resolve('less');
less.render('.test {width: 1+1px;}', function(e, output){
console.log(output.css);
});
3) I start in the console (phpStorm, there is a standard terminal from Windows) and
C:\OpenServer\domains\less>node compiler
module.js:529
throw err;
^
Error: Cannot find module 'less'
at Function.Module._resolveFilename (module.js:527:15)
at Function.resolve (internal/module.js:18:19)
at Object. (C:\OpenServer\domains\less\compiler.js:1:82)
at Module._compile (module.js:624:30)
at Object.Module._extensions..js (module.js:635:10)
at Module.load (module.js:545:32)
at tryModuleLoad (module.js:508:12)
at Function.Module._load (module .js:500:3)
at Function.Module.runMain (module.js:665:10)
at startup (bootstrap_node.js:187:16)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Kitmanov, 2017-10-17
@k12th

It was necessary to install with --save-dev, not -g.

R
RidgeA, 2017-10-17
@RidgeA

Answer by Konstantin Kitmanov + read the doc on how to properly connect modules in NodeJS.
`require.resolve()` does something very different

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question