UglifyJS using NPM in Windows

jcreamer898 picture jcreamer898 · Jan 5, 2012 · Viewed 9.7k times · Source

I am on a Windows 7 box, and I recently installed the most recent version of Node from NodeJS.org

I then ran...

C:\Users\jcreamer>npm install -g uglify-js  
npm http GET https://registry.npmjs.org/uglify-js  
npm http 304 https://registry.npmjs.org/uglify-js  
C:\Users\jcreamer\AppData\Roaming\npm\uglifyjs -> C:\Users\jcreamer\AppData\Roaming\npm\node_modules\uglify-js\bin\uglifyjs   
[email protected] C:\Users\jcreamer\AppData\Roaming\npm\node_modules\uglify-js

And restarted command prompt, but I still cannot run...

cd c:\inetpub\wwwroot\app\  
node uglifyjs -o app.min.js app.js  

I get this error...

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick  
              ^  
Error: Cannot find module 'C:\Inetpub\wwwroot\analytics\uglifyjs'  
    at Function._resolveFilename (module.js:334:11)  
    at Function._load (module.js:279:25)  
    at Array.0 (module.js:470:10)  
    at EventEmitter._tickCallback (node.js:192:40)  

Is there something else I need to do?

UPDATE
Even after I ran the npm as administartor, if I run

C:\Users\jcreamer>uglifyjs

I get...

C:\Users\jcreamer>"C:\Users\jcreamer\AppData\Roaming\npm\\.\node_modules\uglify-js\bin\uglifyjs"
'"C:\Users\jcreamer\AppData\Roaming\npm\\.\node_modules\uglify-js\bin\uglifyjs"' is not recognized as an internal or external comm
and,
operable program or batch file.

Answer

Tarun picture Tarun · Feb 3, 2013

If you have Windows, Then use the following command

npm -g install uglify-js

the -g flag indicates that this is a global installation and will set the env path.

Working for me. Let me know if it is working for you as well.