Installing Less.js (fresh from cloudhead’s github)
probably making some error with your nodeJS application if you install it not in global mode.
Here are several thing that could be happen :
1. Error: require.paths is removed. Use node_modules folders, or the NODE_PATH environment
Error: require.paths is removed. Use node_modules folders, or the NODE_PATH environment variable instead.
at Function.<anonymous> (module.js:360:11)
at Object.<anonymous> (/home/ubuntu/www/js/nodejs/node_modules/less/lib/less/index.js:5:8)
at Module._compile (module.js:416:26)
at Object..js (module.js:434:10)
at Module.load (module.js:335:31)
at Function._load (module.js:294:12)
at Module.require (module.js:341:17)
at require (module.js:352:17)
at Object.<anonymous> (/home/ubuntu/www/js/nodejs/myapp.js:29:12)
at Module._compile (module.js:416:26)
2. Can’t find module ‘less/parser’
Error: Cannot find module 'less/parser'
at Function._resolveFilename (module.js:318:11)
at Function._load (module.js:263:25)
at Module.require (module.js:341:17)
at require (module.js:352:17)
at Object.<anonymous> (/home/ubuntu/local/node/lib/node_modules/less/lib/less/index.js:9:13)
at Module._compile (module.js:416:26)
at Object..js (module.js:434:10)
at Module.load (module.js:335:31)
at Function._load (module.js:294:12)
at Module.require (module.js:341:17)
So how to make this LessJS working with NodeJS ?
Actually problem is comming from inside Less.js code.
require.paths.unshift(path.join(__dirname, '..'));
So, let fix it!Let make some parameters here.
I using npm (without global) when installing less.js.
I put it on /home/ubuntu/www/nodejs/
I installing nodejs without sudo and install it on ~/local.
In case you don’t get it, check out my Node.JS Installation.
So, first thing to do is editing 2 less files :
index.js in node_modules folder
vim less.js/lib/less/index.js and comment line number 5 :
//require.paths.unshift(path.join(__dirname, '..'));
Do as number 1 on “less.js/bin/lessc” by commenting line number 7 :
//require.paths.unshift(path.join(__dirname, '..', 'lib'));
Build ~/.profile to pointing into your LessJS module
Create this on your ~/.profile:
export PATH=$HOME/local/node/bin:$PATH
export NODE_PATH=/home/ubuntu/node/lib/node_modules:$NODE_PATH
export NODE_PATH=/home/ubuntu/www/nodejs/obrool/node_modules:$NODE_PATH
export NODE_PATH=/home/ubuntu/www/nodejs/obrool/node_modules/less.js/lib:$NODE_PATH
In this example, my less.js located in “/home/ubuntu/www/nodejs/obrool/node_modules”.
You can change it depend in your installation method and folder structure.
Last step “source ~/.profile” to load it NODE_PATH.
Start your node server!
Solution was tested and taken from here.
If youre install Less in Global mode, then you should do point number 3 which pointing into you global node_modules folder.
Thanks folks!