Chart.js not installing with NPM

2019-08-08 00:32发布

问题:

I am trying to install chart.js . Their documentation for how to install the package with NPM is here : http://www.chartjs.org/docs/latest/getting-started/installation.html

It says to enter the following with NPM to install.

npm install chart.js --save

However, it doesn't work for me. I get the followin error in my console when I try to install chart.js with NPM.

C:\Users\Hashim AHmed\Desktop\Hashim\coding\Project_PlasmaBird\yahoo_finance>npm install chart.js --save
npm ERR! not a package (MY PROJECT DIRECTORY)\yahoo_finance\chart.js
npm ERR! addLocal Could not install (MY PROJECT DIRECTORY)\yahoo_finance\chart.js
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" "install" "chart.js" "--save"
npm ERR! node v6.10.3
npm ERR! npm  v3.10.10
npm ERR! path C:\Users\HASHIM~1\AppData\Local\Temp\npm-6480-170f285f\unpack-fccf9cad\package.json
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall open

npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\HASHIM~1\AppData\Local\Temp\npm-6480-170f285f\unpack-fccf9cad\package.json'
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\HASHIM~1\AppData\Local\Temp\npm-6480-170f285f\unpack-fccf9cad\package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! Please include the following file with any support request:
npm ERR!     (mydirectory)\npm-debug.logwing error:

EDIT: As some have pointed out, the error may lie in my Package.json so here is the code of my package file (i have censored out some private info) :

{
  "name": "projectplasma",
  "version": "1.0.0",
  "description": "projectplasma",
  "main": "index.js",
  "dependencies": {
    "colors": "^1.1.2",
    "yahoo-finance": "^0.3.2"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/(my username)/(my repo).git"
  },
  "keywords": [
    "stk"
  ],
  "author": "Hashim",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/(myusername)/(my repo)/issues"
  },
  "homepage": "https://github.com/(my username)/(my repo)#readme"
}

Any ideas of what's going wrong here? I am doing exactly as the documentation is saying. If someone could test install this to see if it is working, that would be great. Thanks

回答1:

You need to have the package.json file in your directory to have this chart.js module saved locally.

To create a package.json file, use the below command,

npm init (which will ask you few questions and will create the file at the end).

Once you create your package.json try executing the npm install chart.js --save command and see if it works.

Hope this helps!