10

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.

3 Answers 3

12

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.

8

Global installs are for command-line utilities.

As you can see the uglifyjs command line utility is dropped into your path, at C:\Users\jcreamer\AppData\Roaming\npm\uglifyjs (which is a link to uglify's bin\uglifyjs as you can see in the output.)

@alessioalex You no longer need admin packages to install a global package. The node MSI installer sets the global default prefix to %APPDATA%\npm, so users have the ability to write to it.

If you're trying to require("uglify-js") in your node program, then you should install it locally, not with the -g. It looks like you're trying to use it as a standalone util, so alessioalex's #2 suggestion is exactly right. Just type uglifyjs to use it, not node uglifyjs.

3
  • 1
    Running just uglifyjs is giving me the '"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. Jan 5, 2012 at 16:03
  • Sure! Before I do that, I want to make sure I am 100% sure I am doing it correctly... So, I should... 1. Run npm -g install uglify-js 2. Run uglifyjs -o app.min.js app.js And that should work? Jan 5, 2012 at 16:07
  • You're doing things ok, the same happens to me. Jan 5, 2012 at 16:10
0

You can do two things:

  1. Run the command prompt with administrator privileges when installing a global package like this one (right click -> Run as administrator).

  2. Instead of node uglifyjs... use uglifyjs directly. Since it's installed globally you don't need to call it with node in front, that makes no sense.

1
  • Tried that, check out my update to the question to see what happened... thanks for your help on this! Jan 5, 2012 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.