Running UglifyJS under node.js generates cannot find module error

7.9k views Asked by At
  1. Running node.js v0.10.15 on windows 7 - installed VIA node-v0.10.15-x86.msi.
  2. Downloaded latest UglifyJS2 library.
  3. Created batch file with syntax:

node "path\to\uglifyjs\bin\uglifyjs" -o "file.min.js" "file.js"

Getting error:

module.js:340
   throw err;
Error: Cannot find module 'source-map'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (D:\Projektid\Tools\uglifyjs\tools\node.js:9:21)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)

What could be the problem?

1

There are 1 answers

2
Seth On BEST ANSWER

It seems that you've used node instead of uglify in the command line. Since uglifyjs is its own CLI, you don't need to call on node. I believe you need to have this installed globally to work as intended.

npm install uglify-js -g

then

uglifyjs "path\to\uglifyjs\bin\uglifyjs" -o "file.min.js" "file.js"

should work.