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 npm Basics (retiring) Installing Packages with npm Managing Dependencies in the package.json File

Why am I getting this npm error?

I am trying to figure out why I got this error instead of what Andrew got when I ran the npm test after I re-installed my packages. I followed the video and this was the end result. I had no choice but to use bycryptjs as as bcrypt would not install on my Windows computer.

Rusie@DESKTOP-05UMA67 MINGW64 ~/Documents/susan_treehouse/npm_basics/managing_dependencies_in_the_package.json_file (master)
$ npm install --save bcryptjs && uninstall --save bcrypt
npm WARN package.json hash_generator@0.0.1 No repository field.
npm WARN package.json hash_generator@0.0.1 No README data
bcryptjs@2.3.0 node_modules\bcryptjs
bash: uninstall: command not found

Rusie@DESKTOP-05UMA67 MINGW64 ~/Documents/susan_treehouse/npm_basics/managing_dependencies_in_the_package.json_file (master)
$ npm install colors --save
npm WARN package.json hash_generator@0.0.1 No repository field.
npm WARN package.json hash_generator@0.0.1 No README data
colors@1.1.2 node_modules\colors

Rusie@DESKTOP-05UMA67 MINGW64 ~/Documents/susan_treehouse/npm_basics/managing_dependencies_in_the_package.json_file (master)
$ npm install mocha --save-dev
npm WARN package.json hash_generator@0.0.1 No repository field.
npm WARN package.json hash_generator@0.0.1 No README data
mocha@3.1.0 node_modules\mocha
├── diff@1.4.0
├── escape-string-regexp@1.0.5
├── json3@3.3.2
├── browser-stdout@1.3.0
├── growl@1.9.2
├── supports-color@3.1.2 (has-flag@1.0.0)
├── commander@2.9.0 (graceful-readlink@1.0.1)
├── debug@2.2.0 (ms@0.7.1)
├── mkdirp@0.5.1 (minimist@0.0.8)
├── glob@7.0.5 (path-is-absolute@1.0.1, fs.realpath@1.0.0, inherits@2.0.3, inflight@1.0.5, once@1.4.0, minimatch@3.0.3)
└── lodash.create@3.1.1 (lodash._basecreate@3.0.3, lodash._isiterateecall@3.0.9, lodash._baseassign@3.2.0)

Rusie@DESKTOP-05UMA67 MINGW64 ~/Documents/susan_treehouse/npm_basics/managing_dependencies_in_the_package.json_file (master)
$ npm test

> hash_generator@0.0.1 test C:\Users\Rusie\Documents\susan_treehouse\npm_basics\managing_dependencies_in_the_package.json_file
> mocha

Warning: Could not find any test files matching pattern: test
No test files found
npm ERR! Test failed.  See above for more details.

3 Answers

Michael Liendo
Michael Liendo
15,326 Points

Did you remove the default script task in your package.json file and replace it with the run task in the video?

I believe I did. Here are my files:

app.js

var unsecurePlainTextPassword = "password";

var colors = require('colors');
var bcryptjs = require('bcryptjs');
bcryptjs.genSalt(10, function(err, salt) {
    bcryptjs.hash(unsecurePlainTextPassword, salt, function(err, hash) {
      console.log(hash.green);
    });
});

.gitignore

node_modules/

package.json

{
  "name": "hash_generator",
  "version": "0.0.1",
  "description": "A password hash generator",
  "main": "app.js",
  "dependencies": {
    "bcryptjs": "^2.3.0",
    "colors": "^1.1.2"
  },
  "devDependencies": {
    "mocha": "^3.1.0"
  },
  "scripts": {
    "test": "mocha"
  },
  "author": "Andrew Chalkley",
  "license": "MIT"
}

and of course, my test file which was called test.txt by default. I tried typing "npm test.txt" and this is what returned and the same returned when I changed the ' "test": "mocha" ' to ' "tests": "mocha" because "tests" was included in the bcryptjs package when I installed it:

Usage: npm <command>

where <command> is one of:
    access, add-user, adduser, apihelp, author, bin, bugs, c,
    cache, completion, config, ddp, dedupe, deprecate, dist-tag,
    dist-tags, docs, edit, explore, faq, find, find-dupes, get,
    help, help-search, home, i, info, init, install, issues, la,
    link, list, ll, ln, login, logout, ls, outdated, owner,
    pack, ping, prefix, prune, publish, r, rb, rebuild, remove,
    repo, restart, rm, root, run-script, s, se, search, set,
    show, shrinkwrap, star, stars, start, stop, t, tag, team,
    test, tst, un, uninstall, unlink, unpublish, unstar, up,
    update, upgrade, v, version, view, whoami

npm <cmd> -h     quick help on <cmd>
npm -l           display full usage info
npm faq          commonly asked questions
npm help <term>  search for help on <term>
npm help npm     involved overview

Specify configs in the ini-formatted file:
    C:\Users\Rusie\.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config

npm@2.15.8 C:\Program Files\nodejs\node_modules\npm

Any help on this would be greatly appreciated. Thanks in advance

Michael Liendo
Michael Liendo
15,326 Points

With tests, you have to specify the root path in your package.json file:

test: ./node_modules/.bin/mocha --reporter spec

note that

 --reporter spec

simply prints out a more verbose message and isn't required

then

npm test

As for your later error with test.txt, that because you have to put the word "run" after npm. So...

npm run test.txt

I changed the path to the root to "test: ./node_modules/.bin/mocha --reporter spec" and I still got some errors. I even tried changing the file from "test" to "tests", which also defaulted to calling the file "tests.txt. These are the errors I got when I ran those combinations:

Rusie@DESKTOP-05UMA67 MINGW64 ~/Documents/susan_treehouse/npm_basics/managing_dependencies_in_the_package.json_file (master)
$ npm test
npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "test"
npm ERR! node v4.4.7
npm ERR! npm  v2.15.8
npm ERR! file C:\Users\Rusie\Documents\susan_treehouse\npm_basics\managing_dependencies_in_the_package.json_file\package.json
npm ERR! code EJSONPARSE

npm ERR! Failed to parse json
npm ERR! Unexpected token '\n' at 15:2
npm ERR! "
npm ERR!  ^
npm ERR! File: C:\Users\Rusie\Documents\susan_treehouse\npm_basics\managing_dependencies_in_the_package.json_file\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! This is not a bug in npm.
npm ERR! Tell the package author to fix their package.json file. JSON.parse

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\Rusie\Documents\susan_treehouse\npm_basics\managing_dependencies_in_the_package.json_file\npm-debug.log

Rusie@DESKTOP-05UMA67 MINGW64 ~/Documents/susan_treehouse/npm_basics/managing_dependencies_in_the_package.json_file (master)
$ npm run test.txt
npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "test.txt"
npm ERR! node v4.4.7
npm ERR! npm  v2.15.8
npm ERR! file C:\Users\Rusie\Documents\susan_treehouse\npm_basics\managing_dependencies_in_the_package.json_file\package.json
npm ERR! code EJSONPARSE

npm ERR! Failed to parse json
npm ERR! Unexpected token '\n' at 15:2
npm ERR! "
npm ERR!  ^
npm ERR! File: C:\Users\Rusie\Documents\susan_treehouse\npm_basics\managing_dependencies_in_the_package.json_file\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! This is not a bug in npm.
npm ERR! Tell the package author to fix their package.json file. JSON.parse

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\Rusie\Documents\susan_treehouse\npm_basics\managing_dependencies_in_the_package.json_file\npm-debug.log

Rusie@DESKTOP-05UMA67 MINGW64 ~/Documents/susan_treehouse/npm_basics/managing_dependencies_in_the_package.json_file (master)
$ ls
app.js  node_modules/  package.json  tests.txt

Rusie@DESKTOP-05UMA67 MINGW64 ~/Documents/susan_treehouse/npm_basics/managing_dependencies_in_the_package.json_file (master)
$ npm run tests
npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "tests"
npm ERR! node v4.4.7
npm ERR! npm  v2.15.8
npm ERR! file C:\Users\Rusie\Documents\susan_treehouse\npm_basics\managing_dependencies_in_the_package.json_file\package.json
npm ERR! code EJSONPARSE

npm ERR! Failed to parse json
npm ERR! Unexpected token '\n' at 15:2
npm ERR! "
npm ERR!  ^
npm ERR! File: C:\Users\Rusie\Documents\susan_treehouse\npm_basics\managing_dependencies_in_the_package.json_file\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! This is not a bug in npm.
npm ERR! Tell the package author to fix their package.json file. JSON.parse

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\Rusie\Documents\susan_treehouse\npm_basics\managing_dependencies_in_the_package.json_file\npm-debug.log

Rusie@DESKTOP-05UMA67 MINGW64 ~/Documents/susan_treehouse/npm_basics/managing_dependencies_in_the_package.json_file (master)
$ npm run tests.txt
npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "tests.txt"
npm ERR! node v4.4.7
npm ERR! npm  v2.15.8
npm ERR! file C:\Users\Rusie\Documents\susan_treehouse\npm_basics\managing_dependencies_in_the_package.json_file\package.json
npm ERR! code EJSONPARSE

npm ERR! Failed to parse json
npm ERR! Unexpected token '\n' at 15:2
npm ERR! "
npm ERR!  ^
npm ERR! File: C:\Users\Rusie\Documents\susan_treehouse\npm_basics\managing_dependencies_in_the_package.json_file\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! This is not a bug in npm.
npm ERR! Tell the package author to fix their package.json file. JSON.parse

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\Rusie\Documents\susan_treehouse\npm_basics\managing_dependencies_in_the_package.json_file\npm-debug.log

Rusie@DESKTOP-05UMA67 MINGW64 ~/Documents/susan_treehouse/npm_basics/managing_dependencies_in_the_package.json_file (master)
$ npm tests

Usage: npm <command>

where <command> is one of:
    access, add-user, adduser, apihelp, author, bin, bugs, c,
    cache, completion, config, ddp, dedupe, deprecate, dist-tag,
    dist-tags, docs, edit, explore, faq, find, find-dupes, get,
    help, help-search, home, i, info, init, install, issues, la,
    link, list, ll, ln, login, logout, ls, outdated, owner,
    pack, ping, prefix, prune, publish, r, rb, rebuild, remove,
    repo, restart, rm, root, run-script, s, se, search, set,
    show, shrinkwrap, star, stars, start, stop, t, tag, team,
    test, tst, un, uninstall, unlink, unpublish, unstar, up,
    update, upgrade, v, version, view, whoami

npm <cmd> -h     quick help on <cmd>
npm -l           display full usage info
npm faq          commonly asked questions
npm help <term>  search for help on <term>
npm help npm     involved overview

Specify configs in the ini-formatted file:
    C:\Users\Rusie\.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config

npm@2.15.8 C:\Program Files\nodejs\node_modules\npm

Rusie@DESKTOP-05UMA67 MINGW64 ~/Documents/susan_treehouse/npm_basics/managing_dependencies_in_the_package.json_file (master)
$ npm run tests.txt
npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "tests.txt"
npm ERR! node v4.4.7
npm ERR! npm  v2.15.8
npm ERR! file C:\Users\Rusie\Documents\susan_treehouse\npm_basics\managing_dependencies_in_the_package.json_file\package.json
npm ERR! code EJSONPARSE

npm ERR! Failed to parse json
npm ERR! Unexpected token '\n' at 15:2
npm ERR! "
npm ERR!  ^
npm ERR! File: C:\Users\Rusie\Documents\susan_treehouse\npm_basics\managing_dependencies_in_the_package.json_file\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! This is not a bug in npm.
npm ERR! Tell the package author to fix their package.json file. JSON.parse

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\Rusie\Documents\susan_treehouse\npm_basics\managing_dependencies_in_the_package.json_file\npm-debug.log

Rusie@DESKTOP-05UMA67 MINGW64 ~/Documents/susan_treehouse/npm_basics/managing_dependencies_in_the_package.json_file (master)
$
Michael Liendo
Michael Liendo
15,326 Points

15:2 are you trying to insert a new line in your package.json file? That's what the error is saying.

Instead of putting "test":"mocha", i added the above line that referred to the node modules you suggested with the --reporter spec on the end.