L.Jovi
L.Jovi

Reputation: 1761

npm install less but can't require via node

mac os x 10.10.5

my node and npm version.

node -v
v4.2.1
npm -v
2.14.7

then refer to official website I install less.

sudo npm install -g less
sudo npm install -g less-plugin-clean-css

and I confirm that successfully installed in node_modules

ls /usr/local/lib/node_modules/

appcelerator    generator-webapp    ios-sim         yo
bower           grunt-cli       less
cordova         gulp            less-plugin-clean-css
express         ionic           npm

but when I use node command line to require less, some error occured..

> var less = require('less')
Error: Cannot find module 'less'
    at Function.Module._resolveFilename (module.js:337:15)
    at Function.Module._load (module.js:287:25)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at repl:1:12
    at REPLServer.defaultEval (repl.js:164:27)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.<anonymous> (repl.js:393:12)
    at emitOne (events.js:82:20)
> 

I google it but find nothing which could solve it, please some help ..

Upvotes: 0

Views: 303

Answers (3)

GlebkaF
GlebkaF

Reputation: 76

I'm install it locally, without '-g' flag in working folder and now it works. You should open issue on their gitbug if you want to install it correctly globally.

Upvotes: -1

arjun kori
arjun kori

Reputation: 1120

i think your less module in not install perfectly, As you used command sudo npm install -g less It install Less module globally,

Now you redirect your terminal to your project folder and Use the Following Command sudo npm install less ,remember use it without using -g.

For more information you can visit the enter link description here

Upvotes: 1

PatrickD
PatrickD

Reputation: 1156

require doesn't load global modules by default. the modules must be located in the local node_modules folder. If you really want to use global modules, you can set the NODE_PATH env variable (but this is bad practice in my opinion):

export NODE_PATH=/usr/local/lib/node_modules/

Here is some background information.

Upvotes: 1

Related Questions