Package.json not found error when updating using npm-check-updates

971 views Asked by At

I'm trying to update my node packages/modules and a lot of people (many from StackOverflow) recommended 'npm-check-updates' so I downloaded via npm and ran it. It gave me this error and I'm not sure what's wrong. Is something wrong with my PATH variable in system settings or something? I can't seem to find anything useful with searching Google. Thank you! enter image description here

1

There are 1 answers

0
Neeraj Sharma On BEST ANSWER

npm-check-updates node module requires package.json file to check for the versions that your application is currently using. From the code, it looks for particularly package.json in the current directory to read application dependencies and throws an error if the file is not found.

Github Source Code

If package.json file exists, the module checks which packages can be updated to a higher version and are outdated. Once you review the suggestions and manually verifiy, you would want to run the module with -u option, which will automatically upgrade the package.json file with the newer version numbers of the dependencies. Once this is done, you can run npm install to download the latest versions.

Here is an example of running this update.

~/Downloads/hackingedu/project 512-> ./node_modules/npm-check-updates/bin/npm-check-updates 

"babelify" can be updated from 6.0.2 to 6.1.2 (Installed: 6.0.2, Latest: 6.1.2)
"browserify" can be updated from 9.0.8 to 10.2.4 (Installed: 9.0.8, Latest: 10.2.4)
"canvas" can be updated from 1.2.2 to 1.2.3 (Installed: none, Latest: 1.2.3)
"express" can be updated from 4.12.3 to 4.12.4 (Installed: 4.12.3, Latest: 4.12.4)

Run with '-u' to upgrade your package.json
~/Downloads/hackingedu/project 513-> mv package.json package.json.old
~/Downloads/hackingedu/project 514-> ./node_modules/npm-check-updates/bin/npm-check-updates 
package.json not found
~/Downloads/hackingedu/project 515-> mv package.json.old package.json
~/Downloads/hackingedu/project 516-> cat package.json 
{
  "name": "workshop",
  "version": "0.0.1",
  "description": "",
  "dependencies": {
    "babelify": "6.0.2",
    "browserify": "9.0.8",
    "canvas": "1.2.2",
    "express": "4.12.3",
    "gameboy": "0.2.0",
    "socket.io": "1.3.5"
  }
}
~/Downloads/hackingedu/project 517-> ./node_modules/npm-check-updates/bin/npm-check-updates -u

"babelify" can be updated from 6.0.2 to 6.1.2 (Installed: 6.0.2, Latest: 6.1.2)
"browserify" can be updated from 9.0.8 to 10.2.4 (Installed: 9.0.8, Latest: 10.2.4)
"canvas" can be updated from 1.2.2 to 1.2.3 (Installed: none, Latest: 1.2.3)
"express" can be updated from 4.12.3 to 4.12.4 (Installed: 4.12.3, Latest: 4.12.4)

package.json upgraded
~/Downloads/hackingedu/project 518-> cat package.json 
{
  "name": "workshop",
  "version": "0.0.1",
  "description": "",
  "dependencies": {
    "babelify": "6.1.2",
    "browserify": "10.2.4",
    "canvas": "1.2.3",
    "express": "4.12.4",
    "gameboy": "0.2.0",
    "socket.io": "1.3.5"
  }
}

It is recommended to use semantic versioning in your package.json file, you can learn more on package.json best practices.