【发布时间】:2021-01-26 00:35:51
【问题描述】:
我是一名新程序员,我对 node.js 或任何这些东西都不是很了解。 我的主要问题不是代码错误本身,而是无法在 Visual Studio Code 中安装 discord.js。
我尝试在终端和 cmd 中运行的命令是“npm install discord.js”,但都对我不起作用。
输出:
npm ERR! path C:\Program Files\nodejs\node_modules\npm\node_modules\cacache\node_modules\unique-filename\package.json
npm ERR! Cannot find module 'C:\Program Files\nodejs\node_modules\npm\node_modules\cacache\node_modules\unique-filename\index.js'. Please verify that the package.json has a valid "main" entry
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Dezkah\AppData\Roaming\npm-cache\_logs\2020-10-11T14_35_47_984Z-debug.log
我确实安装了 package.json 文件
{
"name": "bot",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
对不起,如果这个问题很愚蠢或其他什么,但我似乎无法找到解决方案。 提前致谢!
【问题讨论】:
-
您的 package.js 没有
main属性。它应该类似于"main": "index.js" -
我很确定它确实如此
{ "name": "bot", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC" } -
你保存你的 package.json 了吗?我能够使用您的 package.json 文件并安装 discord.js 没有问题。
-
如何保存?我很确定我确实保存了它当我打开 vsCode 我可以看到 package.json
标签: node.js npm discord.js