14

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:

winston@0.7.2 /usr/local/lib/node_modules/winston
├── cycle@1.0.2
├── stack-trace@0.0.7
├── eyes@0.1.8
├── colors@0.6.2
├── async@0.2.9
├── pkginfo@0.3.0
└── request@2.16.6 (forever-agent@0.2.0, aws-sign@0.2.0, tunnel-agent@0.2.0, oauth-sign@0.2.0, json-stringify-safe@3.0.0, cookie-jar@0.2.0, node-uuid@1.4.1, mime@1.2.11, qs@0.5.6, hawk@0.10.2, form-data@0.0.10)

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.

hba
  • 7,406
  • 10
  • 63
  • 105
  • 1
    You could always install winston locally, in the same directory as your program. – Amal Antony Oct 15 '13 at 17:05
  • installing it locally worked, but I don't understand how come on my other vm installing globally worked. Thanks for your help. – hba Oct 15 '13 at 23:52

5 Answers5

13

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
Tom Grant
  • 2,027
  • 18
  • 22
7

You probably need to export NODE_PATH=/usr/local/lib/node_modules, where /usr/local/lib/node_modules is the path where your node modules are globally installed.

fakewaffle
  • 2,981
  • 1
  • 18
  • 15
0

In general, missing modules should be solved by setting NODE_PATH as @fakewaffle says. Assuming they're installed of course.

But for winston, this didn't work for me. For some reason, I had to update file permissions:

chmod o+rx -R /pathto/node_modules/winston

I don't know why it permissions get set incorrectly. This solution is for Ubuntu, presumably it works for other linuxes but not Windows.

Mark
  • 18,730
  • 7
  • 107
  • 130
0

npm WARN winston-daily-rotate-file@3.2.3 requires a peer of winston@^2 || ^3 but none is installed. You must install peer dependencies yourself.

and i have removed node_modules folder and made npm install to dependency. it worked

Note: check before deleting the that you have package.json

"winston": "^2.4.1", "winston-daily-rotate-file": "^3.0.0"

Community
  • 1
  • 1
0

if you use

yarn

-> do yarn install before yarn run dev.