Cannot find module 'winston'

hba picture hba · Oct 15, 2013 · Viewed 20.2k times · Source

I wrote a little module that uses winston to log stuff.

I used sudo npm install -g winston (it is on a vm...so i'm not too concerned with sudo, etc.

Log from npm:

[email protected] /usr/local/lib/node_modules/winston
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])

When I try to run my module in node I get:

Error: Cannot find module 'winston'
    at Function.Module._resolveFilename (module.js:331:15)
    at Function.Module._load (module.js:273:25)
    at Module.require (module.js:357:17)
    at require (module.js:373:17)
    at Object.<anonymous> (/home/name/Code/neon/neon-js-spike/logger.js:2:9)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:349:32)
    at Function.Module._load (module.js:305:12)
    at Module.require (module.js:357:17)

System versions: ubuntu node -v = v0.11.7-pre npm -v = 1.3.8

P.S. I tried this on my home laptop (another ubuntu vm) and worked.

Answer

Tom Grant picture Tom Grant · Nov 21, 2013

If the suggestion of setting the class path hasn't worked, it might likely be that you need to use an npm link. See: http://blog.nodejs.org/2011/04/06/npm-1-0-link/

For winston goto the root folder of your script and use the command:

npm link winston