Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

UglifyJS using NPM in Windows

UglifyJS using NPM in Windows

Problem

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.
Problem courtesy of: jcreamer898

Solution

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.

Solution courtesy of: isaacs

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

UglifyJS using NPM in Windows

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×