我安装了nodejs
我安装了 npm
我使用 -g
选项安装了 less
但是当我通过控制台运行 nodejs 并编写命令 less
时,有:
ReferenceError: less is not defined
at repl:1:2
at REPLServer.self.eval (repl.js:110:21)
at Interface.<anonymous> (repl.js:239:12)
at Interface.EventEmitter.emit (events.js:95:17)
at Interface._onLine (readline.js:202:10)
at Interface._line (readline.js:531:8)
at Interface._ttyWrite (readline.js:760:14)
at ReadStream.onkeypress (readline.js:99:10)
at ReadStream.EventEmitter.emit (events.js:98:17)
at emitKey (readline.js:1095:12)
我可以运行 less
或 lessc
,但在 nodejs 之外
回答回复:
var less = require('less');
Error: Cannot find module 'less'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at repl:1:12
at REPLServer.self.eval (repl.js:110:21)
at repl.js:249:20
at REPLServer.self.eval (repl.js:122:7)
at Interface.<anonymous> (repl.js:239:12)
at Interface.EventEmitter.emit (events.js:95:17)
我需要它用于 Assetic Symfony2
当我尝试通过 symfony2 控制台执行 assetic:dump 时,我遇到了与我在 nodejs“环境”中运行它时遇到的错误相同的错误...
最佳答案
您需要要求模块:
var less = require('less')
http://lesscss.org/#usage在 Node 中有一个示例(搜索代码中的用法小节):
var less = require('less');
less.render('.class { width: (1 + 1) }', function (e, css) {
console.log(css);
});
关于css - NodeJS 看不到 LESS,尽管它是使用全局选项安装的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17814775/