当我运行 Grunt 时,我收到以下消息:本地的 npm 模块 “grunt-contrib-copy” 未找到。它是否已安装?

11

我一直在尝试安装Grunt。当我运行grunt时,我收到以下消息和警告列表:

Local Npm module "grunt-contrib-copy" not found.  Is it installed?
Local Npm module "grunt-contrib-uglify" not found.  Is it installed?
Local Npm module "grunt-contrib-jshint" not found.  Is it installed?
Local Npm module "grunt-contrib-less" not found.  Is it installed?
Local Npm module "grunt-contrib-clean" not found.  Is it installed?
Local Npm module "grunt-contrib-watch" not found.  Is it installed?
Local Npm module "grunt-contrib-concurrent" not found.  Is it installed?
Local Npm module "grunt-contrib-nodemon" not found.  Is it installed?
Local Npm module "grunt-contrib-newer" not found.  Is it installed?
Warning: Task "copy:vendor" not found. Use --force to continue.
Aborted due to warnings.

我尝试了 "npm install"、"npm install grunt --save-dev"、"grunt init:node" 来解决问题,但都没有成功。有人能帮忙吗?谢谢。

有 package.json 文件吗?有 node_modules 文件夹吗? - Rahat Mahbub
你能展示你的Gruntfile.js和package.json文件吗? - VDarricau
3个回答

12

看起来你还没有在Gruntfile.js中加载模块,或者你没有安装所有模块。尝试为所有模块使用npm install <module-name> --save-dev


这是我的 Gruntfile.js 文件: - Brian
有node_modules文件夹、Gruntfile.js和package.json。由于代码太多,我无法输入Gruntfile.js和package.json的代码。我应该安装哪些缺失的模块?它们被称为“copy”或“uglify”等吗?例如,在package.json中,我看到... - Brian
尝试运行 npm install grunt-contrib-copy --save-dev - VDarricau
是的,它确实存在;我输入了正确的内容。但我仍然得到之前相同的错误信息。 - Brian
2
有时候你的最后一次“npm install”可能会失败,因此某些模块未能成功安装,但npm认为它们已经成功安装了。如果你有正确的package.json文件,你可以尝试删除整个node_modules文件夹并运行“npm install”来重新安装所有模块。 - sayume
显示剩余4条评论

1

运行grunt需要一个package.json和Gruntfile.js文件。将文件package.json和Gruntfile放在项目的根目录中。之后,它就可以工作了。

错误:

enter image description here

将文件 package.json 和 Gruntfile 保留在根目录中:

enter image description here


1
在我的情况下,node_modulesgruntFile.js 的父目录中。
有点奇怪,但可能会有帮助。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接