Cannot find module 'winston'

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.

2

5 Answers

If the suggestion of setting the class path hasn't worked, it might likely be that you need to use an npm link. See:

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

npm link winston
1

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.

1

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.

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 folderand 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"

if you use

yarn

-> do yarn install before yarn run dev.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like