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

Brian Patterson
Brian Patterson
19,588 Points

Getting an error in console when running scripts.

I am getting the following error when running the scripts.

➜  taskRunner npm run copy-files
npm ERR! file /Users/briankaty1/Dropbox/JavaScript/taskRunner/package.json
npm ERR! code EJSONPARSE
npm ERR! Failed to parse json
npm ERR! Unexpected token 
npm ERR!  in JSON at position 211 while parsing '{
npm ERR!   "name": "dice_simulator_2015",
npm ERR!   "ve'
npm ERR! File: /Users/briankaty1/Dropbox/JavaScript/taskRunner/package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR! 
npm ERR! Tell the package author to fix their package.json file. JSON.parse

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/briankaty1/.npm/_logs/2018-02-23T16_27_17_508Z-debug.log

This is my package.json file.

{
  "name": "dice_simulator_2015",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "directories": {
    "test": "test"
  },
  "scripts": {
  "uglify": "uglifyjs src/models/* src/frontend.js -m
 -c -o build/app.js",
  "copy-files": "cp src/*.html build/ & cp src/*.css build/"
  },
  "keywords": [
    "dice"
  ],
  "author": "Brian Patterson",
  "license": "MIT"
}

Not sure what I am doing wrong.

1 Answer

Romain Gaget
Romain Gaget
24,449 Points

it seems to be a carriage return on the uglify property that causing the problem.Try to paste you json in this json validator https://jsonlint.com/.

Instead of

"uglify": "uglifyjs src/models/* src/frontend.js -m
 -c -o build/app.js",

try

 "uglify": "uglifyjs src/models/* src/frontend.js -m-c -o build/app.js",
Brian Patterson
Brian Patterson
19,588 Points

No that does not work. I am now getting this error.

> dice_simulator_2015@1.0.0 build /Users/briankaty1/Dropbox/JavaScript/taskRunner
> npm run copy-files && npm run uglify


> dice_simulator_2015@1.0.0 copy-files /Users/briankaty1/Dropbox/JavaScript/taskRunner
> cp src/*.html build/ & cp src/*.css build/


> dice_simulator_2015@1.0.0 uglify /Users/briankaty1/Dropbox/JavaScript/taskRunner
> uglifyjs src/models/* src/frontend.js -m-c -o build/app.js

sh: uglifyjs: command not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! dice_simulator_2015@1.0.0 uglify: `uglifyjs src/models/* src/frontend.js -m-c -o build/app.js`
npm ERR! spawn ENOENT
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!     /Users/briankaty1/.npm/_logs/2018-02-24T11_25_36_564Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! dice_simulator_2015@1.0.0 build: `npm run copy-files && npm run uglify`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the dice_simulator_2015@1.0.0 build 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!     /Users/briankaty1/.npm/_logs/2018-02-24T11_25_36_631Z-debug.log
➜  taskRunner npm install                
npm WARN dice_simulator_2015@1.0.0 No description
npm WARN dice_simulator_2015@1.0.0 No repository field.

up to date in 0.085s

This is what I get when I run npm run build

Mike Hatch
Mike Hatch
14,940 Points

Thanks Romain. Brian, this was the actual issue and Romain solved it. There is no space between the -m and the -c. This is exactly what was happening to me as well. A possible bug issue with Workspace? That is one awefully ugly long line of code as it is. No wonder it's called uglify! Yuck.