Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Creating Your Own Arbitrary Tasks

Bozhong Tao
Bozhong Tao
18,365 Points

Getting "Error: ENOENT: no such file or directory" when running "npm run uglify" task

I could produce the correct output all the way till this uglify task. Then I got this error below:

PS H:\TeamTreeHouse\Full Stack JavaScript\Using npm as a Task Runner\DiceSimulator2015> npm run uglify

> dice_simulator_2015@1.0.0 uglify H:\TeamTreeHouse\Full Stack JavaScript\Using npm as a Task Runner\DiceSimulator2015
> uglifyjs src/models/* src/frontend.js -m -c -o build/app.js

fs.js:646
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^

Error: ENOENT: no such file or directory, open 'H:\TeamTreeHouse\Full Stack JavaScript\Using npm as a Task Runner\DiceSimulator2015\build\app.js'
    at Object.fs.openSync (fs.js:646:18)
    at Object.fs.writeFileSync (fs.js:1299:33)
    at done (H:\TeamTreeHouse\Full Stack JavaScript\Using npm as a Task Runner\DiceSimulator2015\node_modules\uglify-js\bin\uglifyjs:527:16)
    at cb (H:\TeamTreeHouse\Full Stack JavaScript\Using npm as a Task Runner\DiceSimulator2015\node_modules\uglify-js\bin\uglifyjs:324:39)
    at H:\TeamTreeHouse\Full Stack JavaScript\Using npm as a Task Runner\DiceSimulator2015\node_modules\uglify-js\bin\uglifyjs:391:9
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:511:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! dice_simulator_2015@1.0.0 uglify: `uglifyjs src/models/* src/frontend.js -m -c -o build/app.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the dice_simulator_2015@1.0.0 uglify script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\taobo33\AppData\Roaming\npm-cache\_logs\2018-05-23T18_13_32_735Z-debug.log
PS H:\TeamTreeHouse\Full Stack JavaScript\Using npm as a Task Runner\DiceSimulator2015>

I have no idea what went wrong...my package.jason are as below:

{
  "name": "dice_simulator_2015",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "test": "mocha",
    "uglify": "uglifyjs src/models/* src/frontend.js -m -c -o build/app.js"
  },
  "author": "Andrew Chalkley",
  "license": "MIT",
  "devDependencies": {
    "mocha": "^2.2.5",
    "uglify-js": "^2.4.23"
  }
}

all the other files are in the right place and I can run "npm test" fine before this step. I've compared the typing more than twice to make sure it's not a typo. Some help would be appreciated here @@.

(PS. I ran npm command from Windows Power Shell as Admin)

2 Answers

Adam Beer
Adam Beer
11,314 Points

What is the last command what you use? You installed the "npm i uglify-js"?

Bozhong Tao
Bozhong Tao
18,365 Points

Hi Adam Beer thanks for the advise :) Yes I have uglify-js successfully installed. After watching the video for another time I suddenly realized that this is me making a silly mistake... I choose to practice on my local machine, however I didn't create a build folder like the work-space had in the first place. That's why I get the following prompt.

Error: ENOENT: no such file or directory, open 'H:\TeamTreeHouse\Full Stack JavaScript\Using npm as a Task Runner\DiceSimulator2015\build\app.js'

Now it's working properly after the directory to copy to has been created :) Thanks again!