Chart.js 没有使用 NPM 安装

Chart.js not installing with NPM

我正在尝试安装 chart.js。他们关于如何使用 NPM 安装包的文档在这里:http://www.chartjs.org/docs/latest/getting-started/installation.html

说用npm输入以下内容安装

npm install chart.js --save

但是,它对我不起作用。当我尝试使用 NPM 安装 chart.js 时,我的控制台出现以下错误。

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:

编辑:正如一些人所指出的,错误可能出在我的 Package.json 所以这里是我的包文件的代码(我已经删除了一些私人信息):

{
  "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"
}

知道这里出了什么问题吗?我完全按照文档所说的那样做。如果有人可以测试安装它以查看它是否正常工作,那就太好了。谢谢

您的目录中需要 package.json 文件才能在本地保存此 chart.js 模块。

要创建 package.json 文件,请使用以下命令,

npm init(它会问你几个问题,最后会创建文件)。

创建 package.json 后,尝试执行 npm install chart.js --save 命令,看看它是否有效。

希望对您有所帮助!

我在使用 npm 安装 chart.js 时遇到了同样的问题。

看来你必须停止 ng serve 然后尝试 npm install chart.js --save 因为我尝试了相同,并且在同一文件夹中工作正常。

我在后台 运行 webpack server 时遇到了同样的问题 当我关闭本地服务器时,软件包安装没有问题。